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

Subversion Repositories ao486

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 alfik
////////////////////////////////////////////////////////////////////////
2
// $Id: ctrl_xfer_pro.cc 11107 2012-03-25 19:07:17Z sshwarts $
3
/////////////////////////////////////////////////////////////////////////
4
//
5
//  Copyright (C) 2001-2009  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
#define NEED_CPU_REG_SHORTCUTS 1
23
#include "bochs.h"
24
#include "cpu.h"
25
#define LOG_THIS BX_CPU_THIS_PTR
26
 
27
/* pass zero in check_rpl if no needed selector RPL checking for
28
   non-conforming segments */
29
void BX_CPU_C::check_cs(bx_descriptor_t *descriptor, Bit16u cs_raw, Bit8u check_rpl, Bit8u check_cpl)
30
{
31
  // descriptor AR byte must indicate code segment else #GP(selector)
32
  if (descriptor->valid==0 || descriptor->segment==0 ||
33
          IS_DATA_SEGMENT(descriptor->type))
34
  {
35
    BX_ERROR(("check_cs(0x%04x): not a valid code segment !", cs_raw));
36
    exception(BX_GP_EXCEPTION, cs_raw & 0xfffc);
37
  }
38
 
39
#if BX_SUPPORT_X86_64
40
  if (long_mode()) {
41
    if (descriptor->u.segment.l && descriptor->u.segment.d_b) {
42
      BX_ERROR(("check_cs(0x%04x): Both CS.L and CS.D_B bits enabled !", cs_raw));
43
      exception(BX_GP_EXCEPTION, cs_raw & 0xfffc);
44
    }
45
  }
46
#endif
47
 
48
  // if non-conforming, code segment descriptor DPL must = CPL else #GP(selector)
49
  if (IS_CODE_SEGMENT_NON_CONFORMING(descriptor->type)) {
50
    if (descriptor->dpl != check_cpl) {
51
      BX_ERROR(("check_cs(0x%04x): non-conforming code seg descriptor dpl != cpl, dpl=%d, cpl=%d",
52
         cs_raw, descriptor->dpl, check_cpl));
53
      exception(BX_GP_EXCEPTION, cs_raw & 0xfffc);
54
    }
55
 
56
    /* RPL of destination selector must be <= CPL else #GP(selector) */
57
    if (check_rpl > check_cpl) {
58
      BX_ERROR(("check_cs(0x%04x): non-conforming code seg selector rpl > cpl, rpl=%d, cpl=%d",
59
         cs_raw, check_rpl, check_cpl));
60
      exception(BX_GP_EXCEPTION, cs_raw & 0xfffc);
61
    }
62
  }
63
  // if conforming, then code segment descriptor DPL must <= CPL else #GP(selector)
64
  else {
65
    if (descriptor->dpl > check_cpl) {
66
      BX_ERROR(("check_cs(0x%04x): conforming code seg descriptor dpl > cpl, dpl=%d, cpl=%d",
67
         cs_raw, descriptor->dpl, check_cpl));
68
      exception(BX_GP_EXCEPTION, cs_raw & 0xfffc);
69
    }
70
  }
71
 
72
  // code segment must be present else #NP(selector)
73
  if (! descriptor->p) {
74
    BX_ERROR(("check_cs(0x%04x): code segment not present !", cs_raw));
75
    exception(BX_NP_EXCEPTION, cs_raw & 0xfffc);
76
  }
77
}
78
 
79
  void BX_CPP_AttrRegparmN(3)
80
BX_CPU_C::load_cs(bx_selector_t *selector, bx_descriptor_t *descriptor, Bit8u cpl)
81
{
82
  // Add cpl to the selector value.
83
  selector->value = (0xfffc & selector->value) | cpl;
84
 
85
  touch_segment(selector, descriptor);
86
 
87
#ifdef BX_SUPPORT_CS_LIMIT_DEMOTION
88
  // Handle special case of CS.LIMIT demotion (new descriptor limit is
89
  // smaller than current one)
90
  if (BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.u.segment.limit_scaled > descriptor->u.segment.limit_scaled)
91
    BX_CPU_THIS_PTR iCache.flushICacheEntries();
92
#endif
93
 
94
  BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector = *selector;
95
  BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache = *descriptor;
96
  BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].selector.rpl = cpl;
97
  BX_CPU_THIS_PTR sregs[BX_SEG_REG_CS].cache.valid  = 1;
98
 
99
#if BX_SUPPORT_X86_64
100
  if (long_mode()) {
101
    handleCpuModeChange();
102
  }
103
#endif
104
 
105
  updateFetchModeMask(/* CS reloaded */);
106
 
107
#if BX_CPU_LEVEL >= 4
108
  handleAlignmentCheck(/* CPL change */);
109
#endif
110
 
111
  // Loading CS will invalidate the EIP fetch window.
112
  invalidate_prefetch_q();
113
}
114
 
115
void BX_CPU_C::branch_far32(bx_selector_t *selector,
116
           bx_descriptor_t *descriptor, Bit32u eip, Bit8u cpl)
117
{
118
  /* instruction pointer must be in code segment limit else #GP(0) */
119
  if (eip > descriptor->u.segment.limit_scaled) {
120
    BX_ERROR(("branch_far32: EIP > limit"));
121
    exception(BX_GP_EXCEPTION, 0);
122
  }
123
 
124
  /* Load CS:IP from destination pointer */
125
  /* Load CS-cache with new segment descriptor */
126
  load_cs(selector, descriptor, cpl);
127
 
128
  /* Change the EIP value */
129
  EIP = eip;
130
}
131
 
132
void BX_CPU_C::branch_far64(bx_selector_t *selector,
133
           bx_descriptor_t *descriptor, bx_address rip, Bit8u cpl)
134
{
135
#if BX_SUPPORT_X86_64
136
  if (long_mode() && descriptor->u.segment.l) {
137
    if (! IsCanonical(rip)) {
138
      BX_ERROR(("branch_far64: canonical RIP violation"));
139
      exception(BX_GP_EXCEPTION, 0);
140
    }
141
  }
142
  else
143
#endif
144
  {
145
    rip &= 0xffffffff;
146
 
147
    /* instruction pointer must be in code segment limit else #GP(0) */
148
    if (rip > descriptor->u.segment.limit_scaled) {
149
      BX_ERROR(("branch_far64: RIP > limit"));
150
      exception(BX_GP_EXCEPTION, 0);
151
    }
152
  }
153
 
154
  /* Load CS:IP from destination pointer */
155
  /* Load CS-cache with new segment descriptor */
156
  load_cs(selector, descriptor, cpl);
157
 
158
  /* Change the RIP value */
159
  RIP = rip;
160
}

powered by: WebSVN 2.1.0

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