Commit Graph

237 Commits

Author SHA1 Message Date
Peter Tattam
67082a5b50 Implemented SWAPGS instruction.
Note that it is unusual to decode (see SGDT instruction)
2002-09-25 14:09:08 +00:00
Bryce Denney
8f9bec3919 - remove unused, and incorrect MSR fields 2002-09-25 13:26:04 +00:00
Peter Tattam
a0d90e9b39 Implemented SYSCALL and SYSRET as part of x86-64 emulation.
Since the SYSCALL replaces the LOADALL instruction, it is incompatible with
earlier CPU types.

At moment, the SYSCALL is only enabled by x86-64 emulation, but the code
can be incorporated in IA32 only emulations.

Instructions added:

0F 05		SYSCALL		(replaces LOADALL)
0F 07		SYSRET		(new)

TODO:  restructure #if ... so that it can be used by non x86-64 emulations.
2002-09-25 12:54:41 +00:00
Peter Tattam
0de63e8492 Fix to stop external debugger trapping for all exceptions. 2002-09-25 06:36:42 +00:00
Bryce Denney
e3539d7a4a - from Peter Tattam: add missing instruction MOVNTI to decode table 2002-09-25 03:32:12 +00:00
Bryce Denney
8e103b3ffb - fix compile warning about checking that an unsigned int was >= 0 2002-09-25 01:50:14 +00:00
Kevin Lawton
3c09fdb363 I updated code that was using !!get_CF() (or other arithmetic flag) to
use getB_CF() etc.  getB_CF() and friends are only for a relatively
  small number of cases where a true boolean/binary number (0 or 1) is required
  rather than 0 or non-0 as is returned by get_CF().
2002-09-24 18:33:38 +00:00
Kevin Lawton
aeca26fc04 Declaration of loadSRegLMNominal() is now only defined for 64-bit. 2002-09-24 16:39:33 +00:00
Kevin Lawton
26ebda0775 Got rid of INIT_64_DESCRIPTOR in all places. Added/replaced it with
loadSRegLMNominal() which should be used to load a segment register
  in long-mode with nominal values which are compatible with existing
  checks and expectations for descriptor cache values.

Fixed 64-bit iret to not do a descriptor fetch if SS selector is null.
  Also load SS with loadSRegLMNorminal() in the same case.
2002-09-24 16:35:44 +00:00
Kevin Lawton
6e7e4c2431 Fixed ctrl_xfer_pro.cc for 64-bit iret. Check for null selector
was not correct (used == 0, rather than s&0xffc == 0).  Also,
  with a null SS selector, it was fetching the descriptor anyways.
  Put more code inside the if (selector != NULL) clause.
  For a temporary measure I added the local INIT_64_DESCRIPTOR
  from segment_ctrl_pro.cc, and used it in the case that the
  SS selector is null.  We need to make a real function which
  sets a descriptor in long-mode to nominal values.  I'm going
  to do that next... I can't stand seeing the current hacks.  :^)
2002-09-24 15:41:03 +00:00
Bryce Denney
2684886624 - fix my merging error from previous rev. Instead of putting the 32bit code
inside the else clause of an if statement, I added a return in the 64bit
  code so that it would not continue.
2002-09-24 14:00:10 +00:00
Bryce Denney
6e473648bd - remove extra #endifs that came from merging Peter's and Kevin's code 2002-09-24 13:57:37 +00:00
Bryce Denney
de0e58c2c5 These changes are from Peter Tattam
- fix load_ss, remove load_ss_null
- change the "#if KPL64Hacks" around msr stuff into "#if BX_IGNORE_BAD_MSR"
- remove "#if KPL64Hacks" from BX_CPU_C::can_push
- segment_ctrl_pro.cc: bug fix to ss == null handling in 64 bit mode

Modified: cpu/cpu.h cpu/ctrl_xfer_pro.cc cpu/exception.cc
cpu/proc_ctrl.cc cpu/segment_ctrl_pro.cc cpu/stack_pro.cc
2002-09-24 08:29:06 +00:00
Kevin Lawton
82fd79c546 Fixed/updated/cleaned repeat IO & memcpy speedups for Long mode.
Fixed/updated/cleaned guest2host TLB speedups for Long mode.

I now can boot the Linux x86-64 kernel to the VFS mount message,
using all the accelerations.
2002-09-24 04:43:59 +00:00
Kevin Lawton
281e62d8b1 I integrated my hacks to get Linux/x86-64 booting. To keep
these from interfering from a normal compile here's what I did.
In config.h.in (which will generate config.h after a configure),
I added a #define called KPL64Hacks:

  #define KPL64Hacks

*After* running configure, you must set this by hand.  It will
default to off, so you won't get my hacks in a normal compile.
This will go away soon.  There is also a macro just after that
called BailBigRSP().  You don't need to enabled that, but you
can.  In many of the instructions which seemed like they could
be hit by the fetchdecode64() process, but which also touched
EIP/ESP, I inserted a macro.  Usually this macro expands to nothing.
If you like, you can enabled it, and it will panic if it finds
the upper bits of RIP/RSP set.   This helped me find bugs.

Also, I cleaned up the emulation in ctrl_xfer{8,16,32}.cc.
There were some really old legacy code snippets which directly
accessed operands on the stack with access_linear.  Lots of
ugly code instead of just pop_32() etc.  Cleaning those up,
minimized the number of instructions which directly manipulate
the stack pointer, which should help in refining 64-bit support.
2002-09-24 00:44:56 +00:00
Bryce Denney
caa82a19a0 - print CR* registers on exit
[ 501694 ] cr2 value shown when bochs panics
  http://sourceforge.net/tracker/index.php?func=detail&aid=501694&group_id=12580&atid=362580
2002-09-23 22:10:00 +00:00
Kevin Lawton
91fd4b3745 Added new configure option --enable-host-specific-asms, so the
user can turn on/off use of native host specific inline asm
  statements.  By default, this option is enabled, so you only
  need it to disable inline asms in your compile for now.

Currently only on x86+GCC environments, will inline asm()
  statements be used.  Eventually, other platforms could specify
  some asm()s; probably for endian issues such as byte-swapping
  and unaligned memory accesses.  On x86, there are some inline
  asm()s which do the arithmetic EFLAGS processing so that the
  lazy flags handling is somewhat bypassed.  Eventually, I'll
  add more, at least for the more common instructions.  This
  adds a little extra performance.
2002-09-23 17:59:18 +00:00
Bryce Denney
c6133d926a - uncomment pieces of Peter Tattam's external debugger, but leave them in
an #if BX_EXTERNAL_DEBUGGER block
2002-09-23 15:26:05 +00:00
Bryce Denney
00b2607e6a - added bit definitions of CR4 in comments 2002-09-23 14:45:44 +00:00
Bryce Denney
c9b05afa6d - add "Reserved" bitfields to comments, to make it more complete 2002-09-23 14:38:14 +00:00
Bryce Denney
8b1a27fc7e - I forgot to mention that the previous rev was a patch from Peter Tattam 2002-09-23 14:33:49 +00:00
Bryce Denney
185254e367 - for x86-64, claim that we are an "AuthenticAMD" processor
- return model=2 so that Linux recognizes the processor as having an APIC.
  We don't really know what Hammer returns.
- in SetCR4, allow bits 9 and 10 to be written
2002-09-23 14:31:21 +00:00
Bryce Denney
35d9ad97b9 - from Peter Tattam: change prefetch instructions to nops instead of undefined 2002-09-23 14:25:29 +00:00
Bryce Denney
9810e6ab8d - in CMP_EqId, fix bug in sign extension 2002-09-23 14:25:08 +00:00
Kevin Lawton
30de048055 Enhanced my previous updates, by making sure that both operands
to byte operations in asm() statements use either a byte-accessible
  register (eax,ebx,ecx,edx) or a memory operand with "q" and "mq"
  constraints.
2002-09-23 00:40:58 +00:00
Kevin Lawton
9100d1ab1e Changed "r" constraints to "q", so gcc will emit a byte addressable
register for the x86 asm() tricks.
2002-09-23 00:27:18 +00:00
Kevin Lawton
41929b75bd Moved the "i = &iStorage" line inside the #ifdef bracketing
for iCache support.  It wouldn't hurt anything, but it
  makes the compiler complain of longjmp/fork issues.
2002-09-22 23:42:01 +00:00
Kevin Lawton
6e7a2e91f2 Added more x86 specific asm() code to directly handle eflags return
values for some common instructions (like test/and/cmp).  Only
  compiles in on x86 of course.
2002-09-22 22:22:16 +00:00
Kevin Lawton
4150ae197e Hopefully this fixes "Bugs item #612880", which was due to
the icache pageStamp check too early, before it was known
  that the TLB entry would produce a physical address in
  range of the normal part of physical memory.  PCI accesses
  were causing seg faults because of this.  I haven't tested
  this for PCI.
2002-09-22 21:47:57 +00:00
Bryce Denney
a785453194 - fixed another case of get_##flag##(void) 2002-09-22 19:06:46 +00:00
Bryce Denney
fda29cd55b - in definition of ArithmeticalFlag, we had "getB_##flag##(void)",
which says to paste getB_ with flag and then paste with (.  It should
  be "getB_##flag(void)".  Some preprocessors are complaining about pasting
  the symbol with the paren.
2002-09-22 19:03:24 +00:00
Kevin Lawton
b742ccec7e Changed eflags accessors for get_?F() to use (val32 & (1<<N)) instead
of (1 & (val32>>N)), and added a getB_?F() accessor for special
  cases which need a strict binary value (exactly 0 or 1).  Most
  code only needed a value for logical comparison.  I modified the
  special cases which do need a binary number for shifting and
  comparison between flags, to use the special getB_?F() accessor.

Cleaned up memory.cc functions a little, now that all accesses
  are within a single page.

Fixed a (not very likely encountered) bug in fetchdecode.cc (and
  fetchdecode64.cc) where a 2-byte opcode starting with a prefix
  starts at the last offset on a page.  There were no checks
  on the segment overrides for a boundary condition.  I added them.

The eflags enhancements added just a tiny bit of performance.
2002-09-22 18:22:24 +00:00
Bryce Denney
ac4e5bb6cf - add sanity checks
- don't allow MMX on cpu level < 5.
  - require FPU support on cpu level >= 55
  - don't allow MMX support without FPU support (moved this check from
    cpu/i387.h to config.h)
2002-09-22 16:11:12 +00:00
Bryce Denney
e3e16682df from Peter Tattam: in MOVSX_GqEd, typecast op2 to Bit32s instead of Bit16s 2002-09-22 15:42:09 +00:00
Bryce Denney
6b5192d98a - from Peter Tattam: fixed invalid instructions for 64 bit mode 2002-09-22 15:29:51 +00:00
Bryce Denney
2b7654a37d - fixed "macro expands to nothing" by renaming the macro 2002-09-22 07:23:26 +00:00
Bryce Denney
5933d94c91 - add typecast to Bit32u to avoid lots of useless -Wall warnings. The constant
expression on the right side of the comparison was turning out signed, while
  the expression on the left was unsigned.
2002-09-22 02:53:09 +00:00
Kevin Lawton
7fd744b4ef Oops, I had #ifdef 0'd the code in here to do a test compile,
and forgot to put it back.
2002-09-22 02:07:46 +00:00
Kevin Lawton
3bfeab23c9 Split out JZ/JNZ instructions from JCC because they were called
so frequently.
Coded asm() statements for INC/DEC_ERX() instructions.
Cleaned up the iCache a litle including a bug fix.  The
  generation ID was decrementing the whole field including
  some high meta bits.  That could roll over after 1 Billion
  cycles.  I know only decrement if the field is valid, to
  save the write.
I implemented inline functions which can serve the value of
  the arithmetic flags if they are cached, and redirect to
  the lazy_flags.cc routines if not.
Most of this was just prep work for adding more asm() statements
  for native eflags processing when on x86.
2002-09-22 01:52:21 +00:00
Stanislav Shwartsman
a08834b7f7 MMX cannot be compiled without FPU 2002-09-21 17:24:24 +00:00
Kevin Lawton
e2e219eda0 Modified the way that the register field (low 3 bits of a few opcodes
also extended by the REX.B field on Hammer) is passed to instructions.
I rearranged the bxInstruction_c to free up a field to be used
to pass this info when mod-rm bytes are not used.  This got rid
of the ugly ((i->b1 & 7) + i->rex_b) code.

Probably shaved just a very little run time off Hammer emulation,
and even less on x86-32.  The resultant is a little cleaner anyways.
2002-09-20 23:17:51 +00:00
Bryce Denney
dc18466f15 - fix "fatal error U1083: target macro '' expands to nothing" that
Psyon reported
- clean up remnants of cpu64 merge in configure script, Makefile.in,
  and cpu/Makefile.in
2002-09-20 23:16:23 +00:00
Kevin Lawton
402d02974d Moved the EFLAGS.RF check and clearing of inhibit_mask code
in cpu.cc out of the main loop, and into the asynchronous
events handling.  I went through all the code paths, and
there doesn't seem to be any reason for that code to be
in the hot loop.

Added another accessor for getting instruction data, called
modC0().  A lot of instructions test whether the mod field
of mod-nnn-rm is 0xc0 or not, ie., it's a register operation
and not memory.  So I flag this in fetchdecode{,64}.cc.
This added on the order of 1% performance improvement for
a Win95 boot.

Macroized a few leftover calls to Write_RMV_virtual_xyz()
that didn't get modified in the x86-64 merge.  Really, they
just call the real function for now, but I want to have them
available to do direct writes with the guest2host TLB pointers.
2002-09-20 03:52:59 +00:00
Gregory Alexander
88e64f9521 Fix big endian compile problem. 2002-09-20 03:06:39 +00:00
Kevin Lawton
0cd7346b9c - Added an instruction cache. Size is fixed for the moment,
but if you hand edit cpu/cpu.h, and change BxICacheEntries,
  you can try different sizes.  I'll make this more flexible
  with configure.  For now, use "--enable-icache" with no parameters.

- Modified fetchdecode.cc/fetchdecode64.cc just enough so that
  instructions which encode a direct address now use a memory
  resolution function which just sticks the immediate address
  into rm_addr.  With cached instructions we need this.
2002-09-19 19:17:20 +00:00
Kevin Lawton
4e51dcae40 Converted all the remaining available separate fields in bxInstruction_c
to bitfields.  bxInstruction_c is now 24 bytes, including 4 for
the memory addr resolution function pointer, and 4 for the
execution function pointer (16 + 4 + 4).

Coded more accessors, to abstract access from most code.
2002-09-18 08:00:43 +00:00
Kevin Lawton
6723ca9bf4 Moved more separate fields in the bxInstruction_c into bitfields
with accessors.  Had to touch a number of files to update the
access using the new accessors.

Moved rm_addr to the CPU structure, to slim down bxInstruction_c
and to prevent future instruction caching from getting sprayed
with writes to individual rm_addr fields.  There only needs to
be one.  Though need to deal with instructions which have
static non-modrm addresses, but which are using rm_addr since
that will change.

bxInstruction_c is down to about 40 bytes now.  Trying to
get down to 24 bytes.
2002-09-18 05:36:48 +00:00
Bryce Denney
15a3cbc35f - make cpu_param_handler compile with SMP enabled. Unfortunately it will
read all param values from CPU #0.  The only solution I can come up with
  is to change the siminterface handler function interface to pass a void*
  to the callback function.  I'll take care of it eventually.
2002-09-18 04:32:16 +00:00
Kevin Lawton
07b0df2a8a Updated accessing of modrm/sib addressing information to
use accessors.  This lets me work on compressing the
size of fetch-decode structure (now called bxInstruction_c).

I've reduced it down to about 76 bytes.  We should be able
to do much better soon.  I needed the abstraction of the
accessors, so I have a lot of freedom to re-arrange things
without making massive future changes.

Lost a few percent of performance in these mods, but my
main focus was to get the abstraction.
2002-09-17 22:50:53 +00:00
Bryce Denney
f1a3e0307a - add #if BX_CPU_LEVEL>=4 around cr0.wp and cr4 so that i386 will compile 2002-09-17 22:14:33 +00:00