OpenCores
URL https://opencores.org/ocsvn/ao486/ao486/trunk

Subversion Repositories ao486

[/] [ao486/] [trunk/] [bochs486/] [cpu/] [flag_ctrl_pro.cc] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
/////////////////////////////////////////////////////////////////////////
2
// $Id: flag_ctrl_pro.cc 11480 2012-10-03 20:24:29Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2011  The Bochs Project
6
//
7
//  This library is free software; you can redistribute it and/or
8
//  modify it under the terms of the GNU Lesser General Public
9
//  License as published by the Free Software Foundation; either
10
//  version 2 of the License, or (at your option) any later version.
11
//
12
//  This library is distributed in the hope that it will be useful,
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
//  Lesser General Public License for more details.
16
//
17
//  You should have received a copy of the GNU Lesser General Public
18
//  License along with this library; if not, write to the Free Software
19
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA B 02110-1301 USA
20
//
21
/////////////////////////////////////////////////////////////////////////
22
 
23
#define NEED_CPU_REG_SHORTCUTS 1
24
#include "bochs.h"
25
#include "cpu.h"
26
#define LOG_THIS BX_CPU_THIS_PTR
27
 
28
void BX_CPP_AttrRegparmN(1) BX_CPU_C::setEFlags(Bit32u new_eflags)
29
{
30
  Bit32u eflags = BX_CPU_THIS_PTR eflags;
31
 
32
  // VM flag could not be set from long mode
33
#if BX_SUPPORT_X86_64
34
  if (long_mode()) {
35
    if (BX_CPU_THIS_PTR get_VM()) BX_PANIC(("VM is set in long mode !"));
36
    new_eflags &= ~EFlagsVMMask;
37
  }
38
#endif
39
 
40
  BX_CPU_THIS_PTR eflags = new_eflags;
41
  setEFlagsOSZAPC(new_eflags);                  // update lazy flags state
42
 
43
  if (BX_CPU_THIS_PTR get_RF()) invalidate_prefetch_q();
44
 
45
  if (BX_CPU_THIS_PTR get_TF()) {
46
    BX_CPU_THIS_PTR async_event = 1; // TF == 1
47
  }
48
 
49
  if ((eflags ^ new_eflags) & EFlagsIFMask) {
50
    handleInterruptMaskChange();
51
  }
52
 
53
#if BX_CPU_LEVEL >= 4
54
  handleAlignmentCheck(/* EFLAGS.AC reloaded */);
55
#endif
56
 
57
  if ((eflags ^ new_eflags) & EFlagsVMMask) {
58
    handleCpuModeChange(); // VM flag was changed
59
  }
60
}
61
 
62
  void BX_CPP_AttrRegparmN(2)
63
BX_CPU_C::writeEFlags(Bit32u flags, Bit32u changeMask)
64
{
65
  // Build a mask of the non-reserved bits:
66
  // ID,VIP,VIF,AC,VM,RF,x,NT,IOPL,OF,DF,IF,TF,SF,ZF,x,AF,x,PF,x,CF
67
  Bit32u supportMask = 0x00037fd5;
68
#if BX_CPU_LEVEL >= 4
69
  supportMask |= (EFlagsIDMask | EFlagsACMask); // ID/AC
70
#endif
71
#if BX_CPU_LEVEL >= 5
72
  supportMask |= (EFlagsVIPMask | EFlagsVIFMask); // VIP/VIF
73
#endif
74
 
75
  // Screen out changing of any unsupported bits.
76
  changeMask &= supportMask;
77
 
78
  Bit32u newEFlags = (read_eflags() & ~changeMask) | (flags & changeMask);
79
  setEFlags(newEFlags);
80
}
81
 
82
  void BX_CPP_AttrRegparmN(3)
83
BX_CPU_C::write_flags(Bit16u flags, bx_bool change_IOPL, bx_bool change_IF)
84
{
85
  // Build a mask of the following bits:
86
  // x,NT,IOPL,OF,DF,IF,TF,SF,ZF,x,AF,x,PF,x,CF
87
  Bit32u changeMask = 0x0dd5;
88
 
89
#if BX_CPU_LEVEL >= 3
90
  changeMask |= EFlagsNTMask;     // NT is modified as requested.
91
  if (change_IOPL)
92
    changeMask |= EFlagsIOPLMask; // IOPL is modified as requested.
93
#endif
94
  if (change_IF)
95
    changeMask |= EFlagsIFMask;
96
 
97
  writeEFlags(Bit32u(flags), changeMask);
98
}
99
 
100
// Cause arithmetic flags to be in known state and cached in val32.
101
Bit32u BX_CPU_C::force_flags(void)
102
{
103
  Bit32u newflags  = getB_CF();
104
         newflags |= getB_PF() << 2;
105
         newflags |= getB_AF() << 4;
106
         newflags |= getB_ZF() << 6;
107
         newflags |= getB_SF() << 7;
108
         newflags |= getB_OF() << 11;
109
 
110
  BX_CPU_THIS_PTR eflags = (BX_CPU_THIS_PTR eflags & ~EFlagsOSZAPCMask)
111
    | (newflags & EFlagsOSZAPCMask);
112
 
113
  return BX_CPU_THIS_PTR eflags;
114
}
115
 
116
void BX_CPU_C::handleInterruptMaskChange(void)
117
{
118
  if (BX_CPU_THIS_PTR get_IF()) {
119
    // EFLAGS.IF was set, unmask all affected events
120
    unmask_event(BX_EVENT_VMX_INTERRUPT_WINDOW_EXITING |
121
                 BX_EVENT_PENDING_INTR |
122
                 BX_EVENT_PENDING_LAPIC_INTR |
123
                 BX_EVENT_PENDING_VMX_VIRTUAL_INTR);
124
 
125
#if BX_SUPPORT_SVM
126
    if (BX_CPU_THIS_PTR in_svm_guest) {
127
      if ((SVM_V_INTR_PRIO > SVM_V_TPR) || SVM_V_IGNORE_TPR)
128
        unmask_event(BX_EVENT_SVM_VIRQ_PENDING);
129
    }
130
#endif
131
 
132
    return;
133
  }
134
 
135
  // EFLAGS.IF was cleared, some events like INTR would be masked
136
 
137
#if BX_SUPPORT_VMX
138
  if (BX_CPU_THIS_PTR in_vmx_guest && PIN_VMEXIT(VMX_VM_EXEC_CTRL1_EXTERNAL_INTERRUPT_VMEXIT)) {
139
     // if 'External-interrupt exiting' control is set, the value of EFLAGS.IF
140
     // doesn't affect interrupt blocking
141
     mask_event(BX_EVENT_VMX_INTERRUPT_WINDOW_EXITING | BX_EVENT_PENDING_VMX_VIRTUAL_INTR);
142
     return;
143
  }
144
#endif
145
 
146
#if BX_SUPPORT_SVM
147
  if (BX_CPU_THIS_PTR in_svm_guest && SVM_V_INTR_MASKING) {
148
     if (! SVM_HOST_IF)
149
       mask_event(BX_EVENT_PENDING_INTR | BX_EVENT_PENDING_LAPIC_INTR);
150
 
151
     mask_event(BX_EVENT_SVM_VIRQ_PENDING);
152
  }
153
  else
154
#endif
155
  {
156
     mask_event(BX_EVENT_VMX_INTERRUPT_WINDOW_EXITING |
157
                BX_EVENT_PENDING_INTR |
158
                BX_EVENT_PENDING_LAPIC_INTR |
159
                BX_EVENT_PENDING_VMX_VIRTUAL_INTR |
160
                BX_EVENT_SVM_VIRQ_PENDING);
161
  }
162
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.