- update sector count before calling write completion function (SF patch #2144692)
[bochs-mirror.git] / cpu / paging.cc
blobf72033026019b6f5cb05e00e0a61101ef14d25d0
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: paging.cc,v 1.157 2008/09/24 10:39:35 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2001 MandrakeSoft S.A.
6 //
7 // MandrakeSoft S.A.
8 // 43, rue d'Aboukir
9 // 75002 Paris - France
10 // http://www.linux-mandrake.com/
11 // http://www.mandrakesoft.com/
13 // This library is free software; you can redistribute it and/or
14 // modify it under the terms of the GNU Lesser General Public
15 // License as published by the Free Software Foundation; either
16 // version 2 of the License, or (at your option) any later version.
18 // This library is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 // Lesser General Public License for more details.
23 // You should have received a copy of the GNU Lesser General Public
24 // License along with this library; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 /////////////////////////////////////////////////////////////////////////
28 #define NEED_CPU_REG_SHORTCUTS 1
29 #include "bochs.h"
30 #include "cpu.h"
31 #define LOG_THIS BX_CPU_THIS_PTR
33 // X86 Registers Which Affect Paging:
34 // ==================================
36 // CR0:
37 // bit 31: PG, Paging (386+)
38 // bit 16: WP, Write Protect (486+)
39 // 0: allow supervisor level writes into user level RO pages
40 // 1: inhibit supervisor level writes into user level RO pages
42 // CR3:
43 // bit 31..12: PDBR, Page Directory Base Register (386+)
44 // bit 4: PCD, Page level Cache Disable (486+)
45 // Controls caching of current page directory. Affects only the processor's
46 // internal caches (L1 and L2).
47 // This flag ignored if paging disabled (PG=0) or cache disabled (CD=1).
48 // Values:
49 // 0: Page Directory can be cached
50 // 1: Page Directory not cached
51 // bit 3: PWT, Page level Writes Transparent (486+)
52 // Controls write-through or write-back caching policy of current page
53 // directory. Affects only the processor's internal caches (L1 and L2).
54 // This flag ignored if paging disabled (PG=0) or cache disabled (CD=1).
55 // Values:
56 // 0: write-back caching enabled
57 // 1: write-through caching enabled
59 // CR4:
60 // bit 4: PSE, Page Size Extension (Pentium+)
61 // 0: 4KByte pages (typical)
62 // 1: 4MByte or 2MByte pages
63 // bit 5: PAE, Physical Address Extension (Pentium Pro+)
64 // 0: 32bit physical addresses
65 // 1: 36bit physical addresses
66 // bit 7: PGE, Page Global Enable (Pentium Pro+)
67 // The global page feature allows frequently used or shared pages
68 // to be marked as global (PDE or PTE bit 8). Global pages are
69 // not flushed from TLB on a task switch or write to CR3.
70 // Values:
71 // 0: disables global page feature
72 // 1: enables global page feature
74 // page size extention and physical address size extention matrix (legacy mode)
75 // ==============================================================================
76 // CR0.PG CR4.PAE CR4.PSE PDPE.PS PDE.PS | page size physical address size
77 // ==============================================================================
78 // 0 X X R X | -- paging disabled
79 // 1 0 0 R X | 4K 32bits
80 // 1 0 1 R 0 | 4K 32bits
81 // 1 0 1 R 1 | 4M 32bits
82 // 1 1 X R 0 | 4K 36bits
83 // 1 1 X R 1 | 2M 36bits
85 // page size extention and physical address size extention matrix (long mode)
86 // ==============================================================================
87 // CR0.PG CR4.PAE CR4.PSE PDPE.PS PDE.PS | page size physical address size
88 // ==============================================================================
89 // 1 1 X 0 0 | 4K 52bits
90 // 1 1 X 0 1 | 2M 52bits
91 // 1 1 X 1 - | 1G 52bits
94 // Page Directory/Table Entry format when P=0:
95 // ===========================================
97 // 31.. 1: available
98 // 0: P=0
100 // Page Directory Entry format when P=1 (4-Kbyte Page Table):
101 // ==========================================================
103 // 31..12: page table base address
104 // 11.. 9: available
105 // 8: G (Pentium Pro+), 0=reserved otherwise
106 // 7: PS (Pentium+), 0=reserved otherwise
107 // 6: 0=reserved
108 // 5: A (386+)
109 // 4: PCD (486+), 0=reserved otherwise
110 // 3: PWT (486+), 0=reserved otherwise
111 // 2: U/S (386+)
112 // 1: R/W (386+)
113 // 0: P=1 (386+)
115 // Page Table Entry format when P=1 (4-Kbyte Page):
116 // ================================================
118 // 63..63: NX |
119 // 62..52: available | Long mode
120 // 51..32: page base address |
121 // 31..12: page base address
122 // 11.. 9: available
123 // 8: G (Pentium Pro+), 0=reserved otherwise
124 // 7: PAT
125 // 6: D (386+)
126 // 5: A (386+)
127 // 4: PCD (486+), 0=reserved otherwise
128 // 3: PWT (486+), 0=reserved otherwise
129 // 2: U/S (386+)
130 // 1: R/W (386+)
131 // 0: P=1 (386+)
133 // Page Directory/Table Entry Fields Defined:
134 // ==========================================
135 // NX: No Execute
136 // This bit controls the ability to execute code from all physical
137 // pages mapped by the table entry.
138 // 0: Code can be executed from the mapped physical pages
139 // 1: Code cannot be executed
140 // The NX bit can only be set when the no-execute page-protection
141 // feature is enabled by setting EFER.NXE=1, If EFER.NXE=0, the
142 // NX bit is treated as reserved. In this case, #PF occurs if the
143 // NX bit is not cleared to zero.
145 // G: Global flag
146 // Indiciates a global page when set. When a page is marked
147 // global and the PGE flag in CR4 is set, the page table or
148 // directory entry for the page is not invalidated in the TLB
149 // when CR3 is loaded or a task switch occurs. Only software
150 // clears and sets this flag. For page directory entries that
151 // point to page tables, this flag is ignored and the global
152 // characteristics of a page are set in the page table entries.
154 // PS: Page Size flag
155 // Only used in page directory entries. When PS=0, the page
156 // size is 4KBytes and the page directory entry points to a
157 // page table. When PS=1, the page size is 4MBytes for
158 // normal 32-bit addressing and 2MBytes if extended physical
159 // addressing.
161 // PAT: Page-Attribute Table
162 // This bit is only present in the lowest level of the page
163 // translation hierarchy. The PAT bit is the high-order bit
164 // of a 3-bit index into the PAT register. The other two
165 // bits involved in forming the index are the PCD and PWT
166 // bits.
168 // D: Dirty bit:
169 // Processor sets the Dirty bit in the 2nd-level page table before a
170 // write operation to an address mapped by that page table entry.
171 // Dirty bit in directory entries is undefined.
173 // A: Accessed bit:
174 // Processor sets the Accessed bits in both levels of page tables before
175 // a read/write operation to a page.
177 // PCD: Page level Cache Disable
178 // Controls caching of individual pages or page tables.
179 // This allows a per-page based mechanism to disable caching, for
180 // those pages which contained memory mapped IO, or otherwise
181 // should not be cached. Processor ignores this flag if paging
182 // is not used (CR0.PG=0) or the cache disable bit is set (CR0.CD=1).
183 // Values:
184 // 0: page or page table can be cached
185 // 1: page or page table is not cached (prevented)
187 // PWT: Page level Write Through
188 // Controls the write-through or write-back caching policy of individual
189 // pages or page tables. Processor ignores this flag if paging
190 // is not used (CR0.PG=0) or the cache disable bit is set (CR0.CD=1).
191 // Values:
192 // 0: write-back caching
193 // 1: write-through caching
195 // U/S: User/Supervisor level
196 // 0: Supervisor level - for the OS, drivers, etc.
197 // 1: User level - application code and data
199 // R/W: Read/Write access
200 // 0: read-only access
201 // 1: read/write access
203 // P: Present
204 // 0: Not present
205 // 1: Present
206 // ==========================================
209 // Combined page directory/page table protection:
210 // ==============================================
211 // There is one column for the combined effect on a 386
212 // and one column for the combined effect on a 486+ CPU.
214 // +----------------+-----------------+----------------+----------------+
215 // | Page Directory| Page Table | Combined 386 | Combined 486+ |
216 // |Privilege Type | Privilege Type | Privilege Type| Privilege Type|
217 // |----------------+-----------------+----------------+----------------|
218 // |User R | User R | User R | User R |
219 // |User R | User RW | User R | User R |
220 // |User RW | User R | User R | User R |
221 // |User RW | User RW | User RW | User RW |
222 // |User R | Supervisor R | User R | Supervisor RW |
223 // |User R | Supervisor RW | User R | Supervisor RW |
224 // |User RW | Supervisor R | User R | Supervisor RW |
225 // |User RW | Supervisor RW | User RW | Supervisor RW |
226 // |Supervisor R | User R | User R | Supervisor RW |
227 // |Supervisor R | User RW | User R | Supervisor RW |
228 // |Supervisor RW | User R | User R | Supervisor RW |
229 // |Supervisor RW | User RW | User RW | Supervisor RW |
230 // |Supervisor R | Supervisor R | Supervisor RW | Supervisor RW |
231 // |Supervisor R | Supervisor RW | Supervisor RW | Supervisor RW |
232 // |Supervisor RW | Supervisor R | Supervisor RW | Supervisor RW |
233 // |Supervisor RW | Supervisor RW | Supervisor RW | Supervisor RW |
234 // +----------------+-----------------+----------------+----------------+
236 // Page Fault Error Code Format:
237 // =============================
239 // bits 31..4: Reserved
240 // bit 3: RSVD (Pentium Pro+)
241 // 0: fault caused by reserved bits set to 1 in a page directory
242 // when the PSE or PAE flags in CR4 are set to 1
243 // 1: fault was not caused by reserved bit violation
244 // bit 2: U/S (386+)
245 // 0: fault originated when in supervior mode
246 // 1: fault originated when in user mode
247 // bit 1: R/W (386+)
248 // 0: access causing the fault was a read
249 // 1: access causing the fault was a write
250 // bit 0: P (386+)
251 // 0: fault caused by a nonpresent page
252 // 1: fault caused by a page level protection violation
254 // Some paging related notes:
255 // ==========================
257 // - When the processor is running in supervisor level, all pages are both
258 // readable and writable (write-protect ignored). When running at user
259 // level, only pages which belong to the user level are accessible;
260 // read/write & read-only are readable, read/write are writable.
262 // - If the Present bit is 0 in either level of page table, an
263 // access which uses these entries will generate a page fault.
265 // - (A)ccess bit is used to report read or write access to a page
266 // or 2nd level page table.
268 // - (D)irty bit is used to report write access to a page.
270 // - Processor running at CPL=0,1,2 maps to U/S=0
271 // Processor running at CPL=3 maps to U/S=1
273 #if BX_SUPPORT_X86_64
274 #define BX_INVALID_TLB_ENTRY BX_CONST64(0xffffffffffffffff)
275 #else
276 #define BX_INVALID_TLB_ENTRY 0xffffffff
277 #endif
279 // bit [11] of the TLB lpf used for TLB_HostPtr valid indication
280 #define TLB_LPFOf(laddr) AlignedAccessLPFOf(laddr, 0x7ff)
282 #if BX_CPU_LEVEL >= 4
283 # define BX_PRIV_CHECK_SIZE 32
284 #else
285 # define BX_PRIV_CHECK_SIZE 16
286 #endif
288 static unsigned priv_check[BX_PRIV_CHECK_SIZE];
290 // The 'priv_check' array is used to decide if the current access
291 // has the proper paging permissions. An index is formed, based
292 // on parameters such as the access type and level, the write protect
293 // flag and values cached in the TLB. The format of the index into this
294 // array is:
296 // |4 |3 |2 |1 |0 |
297 // |wp|us|us|rw|rw|
298 // | | | | |
299 // | | | | +---> r/w of current access
300 // | | +--+------> u/s,r/w combined of page dir & table (cached)
301 // | +------------> u/s of current access
302 // +---------------> Current CR0.WP value
305 // Each entry in the TLB cache has 3 entries:
307 // lpf: Linear Page Frame (page aligned linear address of page)
308 // bits 32..12 Linear page frame
309 // bit 11 0: TLB HostPtr access allowed, 1: not allowed
310 // bit 10...0 Invalidate index
312 // ppf: Physical Page Frame (page aligned phy address of page)
314 // hostPageAddr:
315 // Host Page Frame address used for direct access to
316 // the mem.vector[] space allocated for the guest physical
317 // memory. If this is zero, it means that a pointer
318 // to the host space could not be generated, likely because
319 // that page of memory is not standard memory (it might
320 // be memory mapped IO, ROM, etc).
322 // accessBits:
324 // bit 31: Page is a global page.
326 // The following bits are used for a very efficient permissions
327 // check. The goal is to be able, using only the current privilege
328 // level and access type, to determine if the page tables allow the
329 // access to occur or at least should rewalk the page tables. On
330 // the first read access, permissions are set to only read, so a
331 // rewalk is necessary when a subsequent write fails the tests.
332 // This allows for the dirty bit to be set properly, but for the
333 // test to be efficient. Note that the CR0.WP flag is not present.
334 // The values in the following flags is based on the current CR0.WP
335 // value, necessitating a TLB flush when CR0.WP changes.
337 // The test is:
338 // OK = (accessBits & ((W<<1) | U)) <> 0 [W:1=Write, 0=Read, U:1=CPL3,0=CPL0-2]
340 // Thus for reads, it is:
341 // OK = ( U )
342 // And for writes:
343 // OK = 0x2 | ( U )
345 // Note, that the TLB should have TLB_HostPtr bit set when direct
346 // access through host pointer is NOT allowed for the page. A memory
347 // operation asking for a direct access through host pointer will
348 // set TLB_HostPtr bit in its lpf field and thus get TLB miss result
349 // when the direct access is not allowed.
352 #define TLB_SysOnly (0x1)
353 #define TLB_ReadOnly (0x2)
355 #define TLB_HostPtr (0x800) /* set this bit when direct access is NOT allowed */
357 #define TLB_GlobalPage (0x80000000)
359 // === TLB Instrumentation section ==============================
361 // Note: this is an approximation of what Peter Tattam had.
363 #define InstrumentTLB 0
365 #if InstrumentTLB
366 static unsigned tlbLookups=0;
367 static unsigned tlbMisses=0;
368 static unsigned tlbGlobalFlushes=0;
369 static unsigned tlbNonGlobalFlushes=0;
371 #define InstrTLB_StatsMask 0xfffff
373 #define InstrTLB_Stats() {\
374 if ((tlbLookups & InstrTLB_StatsMask) == 0) { \
375 BX_INFO(("TLB lookup:%8d miss:%8d %6.2f%% flush:%8d %6.2f%%", \
376 tlbLookups, \
377 tlbMisses, \
378 tlbMisses * 100.0 / tlbLookups, \
379 (tlbGlobalFlushes+tlbNonGlobalFlushes), \
380 (tlbGlobalFlushes+tlbNonGlobalFlushes) * 100.0 / tlbLookups \
381 )); \
382 tlbLookups = tlbMisses = tlbGlobalFlushes = tlbNonGlobalFlushes = 0; \
385 #define InstrTLB_Increment(v) (v)++
387 #else
388 #define InstrTLB_Stats()
389 #define InstrTLB_Increment(v)
390 #endif
392 #define BX_PHY_ADDRESS_MASK ((((Bit64u)(1)) << BX_PHY_ADDRESS_WIDTH) - 1)
394 #define BX_PHY_ADDRESS_RESERVED_BITS \
395 (~BX_PHY_ADDRESS_MASK & BX_CONST64(0xfffffffffffff))
397 // ==============================================================
399 void BX_CPP_AttrRegparmN(2)
400 BX_CPU_C::pagingCR0Changed(Bit32u oldCR0, Bit32u newCR0)
402 // Modification of PG,PE flushes TLB cache according to docs.
403 // Additionally, the TLB strategy is based on the current value of
404 // WP, so if that changes we must also flush the TLB.
405 if ((oldCR0 & 0x80010001) != (newCR0 & 0x80010001))
406 TLB_flush(); // Flush Global entries also.
409 void BX_CPP_AttrRegparmN(2)
410 BX_CPU_C::pagingCR4Changed(Bit32u oldCR4, Bit32u newCR4)
412 // Modification of PGE,PAE,PSE flushes TLB cache according to docs.
413 if ((oldCR4 & 0x000000b0) != (newCR4 & 0x000000b0))
414 TLB_flush(); // Flush Global entries also.
416 #if BX_SUPPORT_PAE
417 if ((oldCR4 & 0x00000020) != (newCR4 & 0x00000020)) {
418 if (BX_CPU_THIS_PTR cr4.get_PAE() && !long_mode())
419 BX_CPU_THIS_PTR cr3_masked = BX_CPU_THIS_PTR cr3 & 0xffffffe0;
420 else
421 BX_CPU_THIS_PTR cr3_masked = BX_CPU_THIS_PTR cr3 & BX_CONST64(0x000ffffffffff000);
423 #endif
426 void BX_CPP_AttrRegparmN(1)
427 BX_CPU_C::SetCR3(bx_address val)
429 // flush TLB even if value does not change
430 #if BX_SUPPORT_GLOBAL_PAGES
431 if (BX_CPU_THIS_PTR cr4.get_PGE())
432 TLB_flushNonGlobal(); // Don't flush Global entries.
433 else
434 #endif
435 TLB_flush(); // Flush Global entries also.
437 #if BX_SUPPORT_PAE
438 if (BX_CPU_THIS_PTR cr4.get_PAE()) {
439 #if BX_SUPPORT_X86_64
440 if (long_mode()) {
441 #if BX_PHY_ADDRESS_WIDTH == 32
442 if (val & BX_CONST64(0x000fffff00000000)) {
443 BX_PANIC(("SetCR3() 0x%08x%08x: Only 32 bit physical address space is emulated !", GET32H(val), GET32L(val)));
445 #endif
446 // bits [63-52], [11-5], [2-0] are reserved
447 if (val & (BX_CONST64(0xfff0000000000000) | BX_PHY_ADDRESS_RESERVED_BITS)) {
448 BX_ERROR(("SetCR3(): Attempt to write to reserved bits of CR3"));
449 exception(BX_GP_EXCEPTION, 0, 0);
452 BX_CPU_THIS_PTR cr3_masked = val & BX_CONST64(0x000ffffffffff000);
454 else
455 #endif
456 BX_CPU_THIS_PTR cr3_masked = val & 0xffffffe0;
458 else
459 #endif
460 BX_CPU_THIS_PTR cr3_masked = val & 0xfffff000;
462 BX_CPU_THIS_PTR cr3 = val;
465 // Called to initialize the TLB upon startup.
466 // Unconditional initialization of all TLB entries.
467 void BX_CPU_C::TLB_init(void)
469 unsigned n, wp, us_combined, rw_combined, us_current, rw_current;
472 // Setup privilege check matrix.
474 for (n=0; n<BX_PRIV_CHECK_SIZE; n++) {
475 wp = (n & 0x10) >> 4;
476 us_current = (n & 0x08) >> 3;
477 us_combined = (n & 0x04) >> 2;
478 rw_combined = (n & 0x02) >> 1;
479 rw_current = (n & 0x01) >> 0;
480 if (wp) { // when write protect on
481 if (us_current > us_combined) // user access, supervisor page
482 priv_check[n] = 0;
483 else if (rw_current > rw_combined) // RW access, RO page
484 priv_check[n] = 0;
485 else
486 priv_check[n] = 1;
488 else { // when write protect off
489 if (us_current == 0) // Supervisor mode access, anything goes
490 priv_check[n] = 1;
491 else {
492 // user mode access
493 if (us_combined == 0) // user access, supervisor Page
494 priv_check[n] = 0;
495 else if (rw_current > rw_combined) // RW access, RO page
496 priv_check[n] = 0;
497 else
498 priv_check[n] = 1;
503 TLB_flush();
506 void BX_CPU_C::TLB_flush(void)
508 #if InstrumentTLB
509 InstrTLB_Increment(tlbGlobalFlushes);
510 #endif
512 invalidate_prefetch_q();
514 for (unsigned n=0; n<BX_TLB_SIZE; n++) {
515 BX_CPU_THIS_PTR TLB.entry[n].lpf = BX_INVALID_TLB_ENTRY;
518 #if BX_SUPPORT_PAE
519 BX_CPU_THIS_PTR PDPE_CACHE.valid = 0;
520 #endif
522 #if BX_SUPPORT_MONITOR_MWAIT
523 // invalidating of the TLB might change translation for monitored page
524 // and cause subsequent MWAIT instruction to wait forever
525 BX_CPU_THIS_PTR monitor.reset_monitor();
526 #endif
529 #if BX_SUPPORT_GLOBAL_PAGES
531 void BX_CPU_C::TLB_flushNonGlobal(void)
533 #if InstrumentTLB
534 InstrTLB_Increment(tlbNonGlobalFlushes);
535 #endif
537 invalidate_prefetch_q();
539 for (unsigned n=0; n<BX_TLB_SIZE; n++) {
540 bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[n];
541 if (!(tlbEntry->accessBits & TLB_GlobalPage))
542 tlbEntry->lpf = BX_INVALID_TLB_ENTRY;
545 #if BX_SUPPORT_PAE
546 BX_CPU_THIS_PTR PDPE_CACHE.valid = 0;
547 #endif
549 #if BX_SUPPORT_MONITOR_MWAIT
550 // invalidating of the TLB might change translation for monitored page
551 // and cause subsequent MWAIT instruction to wait forever
552 BX_CPU_THIS_PTR monitor.reset_monitor();
553 #endif
556 #endif
558 void BX_CPU_C::TLB_invlpg(bx_address laddr)
560 invalidate_prefetch_q();
562 BX_DEBUG(("TLB_invlpg(0x"FMT_ADDRX"): invalidate TLB entry", laddr));
564 unsigned TLB_index = BX_TLB_INDEX_OF(laddr, 0);
565 bx_address lpf = LPFOf(laddr);
566 bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[TLB_index];
567 if (TLB_LPFOf(tlbEntry->lpf) == lpf) {
568 tlbEntry->lpf = BX_INVALID_TLB_ENTRY;
571 #if BX_SUPPORT_PAE
572 BX_CPU_THIS_PTR PDPE_CACHE.valid = 0;
573 #endif
575 #if BX_SUPPORT_MONITOR_MWAIT
576 // invalidating of the TLB entry might change translation for monitored
577 // page and cause subsequent MWAIT instruction to wait forever
578 BX_CPU_THIS_PTR monitor.reset_monitor();
579 #endif
582 void BX_CPP_AttrRegparmN(1) BX_CPU_C::INVLPG(bxInstruction_c* i)
584 #if BX_CPU_LEVEL >= 4
585 if (!real_mode() && CPL!=0) {
586 BX_ERROR(("INVLPG: priveledge check failed, generate #GP(0)"));
587 exception(BX_GP_EXCEPTION, 0, 0);
590 bx_address eaddr = BX_CPU_CALL_METHODR(i->ResolveModrm, (i));
591 bx_address laddr = get_laddr(i->seg(), eaddr);
592 BX_INSTR_TLB_CNTRL(BX_CPU_ID, BX_INSTR_INVLPG, laddr);
593 TLB_invlpg(laddr);
594 #else
595 BX_INFO(("INVLPG: required i486, use --enable-cpu=4 option"));
596 exception(BX_UD_EXCEPTION, 0, 0);
597 #endif
600 // error checking order - page not present, reserved bits, protection
601 #define ERROR_NOT_PRESENT 0x00
602 #define ERROR_PROTECTION 0x01
603 #define ERROR_RESERVED 0x08
604 #define ERROR_CODE_ACCESS 0x10
606 void BX_CPU_C::page_fault(unsigned fault, bx_address laddr, unsigned user, unsigned rw, unsigned access_type)
608 unsigned error_code = fault;
610 error_code |= (user << 2) | (rw << 1);
611 #if BX_SUPPORT_X86_64
612 if (BX_CPU_THIS_PTR efer.get_NXE() && (access_type == CODE_ACCESS))
613 error_code |= ERROR_CODE_ACCESS; // I/D = 1
614 #endif
615 BX_CPU_THIS_PTR cr2 = laddr;
617 #if BX_SUPPORT_X86_64
618 BX_DEBUG(("page fault for address %08x%08x @ %08x%08x",
619 GET32H(laddr), GET32L(laddr), GET32H(RIP), GET32L(RIP)));
620 #else
621 BX_DEBUG(("page fault for address %08x @ %08x", laddr, EIP));
622 #endif
624 exception(BX_PF_EXCEPTION, error_code, 0);
627 /* PAE PML4: bits [51 .. physical address width], [7] - support 1G paging */
628 #define PAGING_PAE_PML4_RESERVED_BITS \
629 (BX_PHY_ADDRESS_RESERVED_BITS/* | BX_CONST64(0x80)*/)
631 /* PAE PDPE: bits [51 .. physical address width], [7] - support 1G paging */
632 #define PAGING_PAE_PDPE_RESERVED_BITS \
633 (BX_PHY_ADDRESS_RESERVED_BITS/* | BX_CONST64(0x80)*/)
635 /* PAE PDE: bits [51 .. physical address width] */
636 #define PAGING_PAE_PDE_RESERVED_BITS (BX_PHY_ADDRESS_RESERVED_BITS)
638 /* PAE PDE4M: bits [51 .. physical address width], [20:13] */
639 #define PAGING_PAE_PDE4M_RESERVED_BITS \
640 (PAGING_PAE_PDE_RESERVED_BITS | BX_CONST64(0x001FE000))
642 /* PAE PTE: bits [51 .. physical address width] */
643 #define PAGING_PAE_PTE_RESERVED_BITS (BX_PHY_ADDRESS_RESERVED_BITS)
645 #define PAGE_DIRECTORY_NX_BIT (BX_CONST64(0x8000000000000000))
647 #if BX_SUPPORT_PAE
649 // Translate a linear address to a physical address in PAE paging mode
650 bx_phy_address BX_CPU_C::translate_linear_PAE(bx_address laddr, Bit32u &combined_access, unsigned curr_pl, unsigned rw, unsigned access_type)
652 bx_phy_address pdpe_addr, ppf;
653 Bit64u pdpe, pde, pte;
654 #if BX_SUPPORT_X86_64
655 Bit64u pml4, pml4_addr = 0;
656 #endif
657 unsigned priv_index, nx_fault = 0;
658 bx_bool isWrite = (rw >= BX_WRITE); // write or r-m-w
659 unsigned pl = (curr_pl == 3);
661 combined_access = 0;
663 #if BX_SUPPORT_X86_64
664 if (long_mode()) {
665 // Get PML4 entry
666 pml4_addr = (bx_phy_address)(BX_CPU_THIS_PTR cr3_masked |
667 ((laddr & BX_CONST64(0x0000ff8000000000)) >> 36));
668 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pml4_addr, 8, &pml4);
669 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pml4_addr, 8, BX_READ, (Bit8u*)(&pml4));
671 if (!(pml4 & 0x1)) {
672 BX_DEBUG(("PML4: entry not present"));
673 page_fault(ERROR_NOT_PRESENT, laddr, pl, isWrite, access_type);
675 #if BX_PHY_ADDRESS_WIDTH == 32
676 if (pml4 & BX_CONST64(0x000fffff00000000)) {
677 BX_PANIC(("PML4 0x%08x%08x: Only 32 bit physical address space is emulated !", GET32H(pml4), GET32L(pml4)));
679 #endif
680 if (pml4 & PAGING_PAE_PML4_RESERVED_BITS) {
681 BX_DEBUG(("PML4: reserved bit is set PML4=%08x:%08x", GET32H(pml4), GET32L(pml4)));
682 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
684 if (pml4 & PAGE_DIRECTORY_NX_BIT) {
685 if (! BX_CPU_THIS_PTR efer.get_NXE()) {
686 BX_DEBUG(("PML4: NX bit set when EFER.NXE is disabled"));
687 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
689 if (access_type == CODE_ACCESS) {
690 BX_DEBUG(("PML4: non-executable page fault occured"));
691 nx_fault = 1;
695 pdpe_addr = (bx_phy_address)((pml4 & BX_CONST64(0x000ffffffffff000)) |
696 ((laddr & BX_CONST64(0x0000007fc0000000)) >> 27));
698 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pdpe_addr, 8, &pdpe);
699 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pdpe_addr, 8, BX_READ, (Bit8u*)(&pdpe));
701 else
702 #endif
704 pdpe_addr = (bx_phy_address) (BX_CPU_THIS_PTR cr3_masked | ((laddr & 0xc0000000) >> 27));
706 if (! BX_CPU_THIS_PTR PDPE_CACHE.valid) {
707 for (int n=0; n<4; n++) {
708 // read PDPE cache entry
709 bx_phy_address entry_pdpe_addr = (bx_phy_address) (BX_CPU_THIS_PTR cr3_masked | (n << 3));
710 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, entry_pdpe_addr, 8, &(BX_CPU_THIS_PTR PDPE_CACHE.entry[n]));
711 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, entry_pdpe_addr, 8,
712 BX_READ, (Bit8u*)(&BX_CPU_THIS_PTR PDPE_CACHE.entry[n]));
714 BX_CPU_THIS_PTR PDPE_CACHE.valid = 1;
717 pdpe = BX_CPU_THIS_PTR PDPE_CACHE.entry[(laddr >> 30) & 3];
720 if (!(pdpe & 0x1)) {
721 BX_DEBUG(("PAE PDPE: entry not present"));
722 page_fault(ERROR_NOT_PRESENT, laddr, pl, isWrite, access_type);
724 #if BX_PHY_ADDRESS_WIDTH == 32
725 if (pdpe & BX_CONST64(0x000fffff00000000)) {
726 BX_PANIC(("PAE PDPE 0x%08x%08x: Only 32 bit physical address space is emulated !", GET32H(pdpe), GET32L(pdpe)));
728 #endif
729 if (pdpe & PAGING_PAE_PDPE_RESERVED_BITS) {
730 BX_DEBUG(("PAE PDPE: reserved bit is set: PDPE=%08x:%08x", GET32H(pdpe), GET32L(pdpe)));
731 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
733 #if BX_SUPPORT_X86_64
734 if (pdpe & PAGE_DIRECTORY_NX_BIT) {
735 if (! BX_CPU_THIS_PTR efer.get_NXE()) {
736 BX_DEBUG(("PDPE: NX bit set when EFER.NXE is disabled"));
737 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
739 if (access_type == CODE_ACCESS) {
740 BX_DEBUG(("PDPE: non-executable page fault occured"));
741 nx_fault = 1;
744 #endif
745 bx_phy_address pde_addr = (bx_phy_address)((pdpe & BX_CONST64(0x000ffffffffff000))
746 | ((laddr & 0x3fe00000) >> 18));
748 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pde_addr, 8, &pde);
749 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pde_addr, 8, BX_READ, (Bit8u*)(&pde));
751 if (!(pde & 0x1)) {
752 BX_DEBUG(("PAE PDE: entry not present"));
753 page_fault(ERROR_NOT_PRESENT, laddr, pl, isWrite, access_type);
755 #if BX_PHY_ADDRESS_WIDTH == 32
756 if (pde & BX_CONST64(0x000fffff00000000)) {
757 BX_PANIC(("PAE PDE 0x%08x%08x: Only 32 bit physical address space is emulated !", GET32H(pde), GET32L(pde)));
759 #endif
760 if (pde & PAGING_PAE_PDE_RESERVED_BITS) {
761 BX_DEBUG(("PAE PDE: reserved bit is set PDE=%08x:%08x", GET32H(pde), GET32L(pde)));
762 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
764 #if BX_SUPPORT_X86_64
765 if (pde & PAGE_DIRECTORY_NX_BIT) {
766 if (! BX_CPU_THIS_PTR efer.get_NXE()) {
767 BX_DEBUG(("PDE: NX bit set when EFER.NXE is disabled"));
768 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
770 if (access_type == CODE_ACCESS) {
771 BX_DEBUG(("PDE: non-executable page fault occured"));
772 nx_fault = 1;
775 #endif
777 // Ignore CR4.PSE in PAE mode
778 if (pde & 0x80) {
779 if (pde & PAGING_PAE_PDE4M_RESERVED_BITS) {
780 BX_DEBUG(("PAE PDE4M: reserved bit is set PDE=%08x:%08x", GET32H(pde), GET32L(pde)));
781 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
784 // Combined access is just access from the pde (no pte involved).
785 combined_access = (pde) & 0x06; // U/S and R/W
786 #if BX_SUPPORT_X86_64
787 if (long_mode()) {
788 combined_access &= (pml4 & pdpe) & 0x06;
790 #endif
792 #if BX_SUPPORT_GLOBAL_PAGES
793 if (BX_CPU_THIS_PTR cr4.get_PGE())
794 combined_access |= (pde & 0x100); // G
795 #endif
797 priv_index =
798 #if BX_CPU_LEVEL >= 4
799 (BX_CPU_THIS_PTR cr0.get_WP() << 4) | // bit 4
800 #endif
801 (pl<<3) | // bit 3
802 (combined_access & 0x06) | // bit 2,1
803 (isWrite); // bit 0
805 if (!priv_check[priv_index] || nx_fault)
806 page_fault(ERROR_PROTECTION, laddr, pl, isWrite, access_type);
808 #if BX_SUPPORT_X86_64
809 if (long_mode()) {
810 // Update PML4 A bit if needed.
811 if (!(pml4 & 0x20)) {
812 pml4 |= 0x20;
813 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pml4_addr, 8, &pml4);
814 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pml4_addr, 8, BX_WRITE, (Bit8u*)(&pml4));
817 #endif
819 // Update PDPE A bit if needed.
820 if (!(pdpe & 0x20)) {
821 pdpe |= 0x20;
822 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pdpe_addr, 8, &pdpe);
823 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pdpe_addr, 8, BX_WRITE, (Bit8u*)(&pdpe));
826 // Update PDE A/D bits if needed.
827 if (((pde & 0x20)==0) || (isWrite && ((pde & 0x40)==0))) {
828 pde |= (0x20 | (isWrite<<6)); // Update A and possibly D bits
829 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pde_addr, 8, &pde);
830 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pde_addr, 8, BX_WRITE, (Bit8u*)(&pde));
833 // Make up the physical page frame address.
834 ppf = (bx_phy_address)((pde & BX_CONST64(0x000fffffffe00000)) | (laddr & 0x001ff000));
836 return ppf;
839 // 4k pages, Get page table entry
840 bx_phy_address pte_addr = (bx_phy_address)((pde & BX_CONST64(0x000ffffffffff000)) |
841 ((laddr & 0x001ff000) >> 9));
843 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pte_addr, 8, &pte);
844 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pte_addr, 8, BX_READ, (Bit8u*)(&pte));
846 if (!(pte & 0x1)) {
847 BX_DEBUG(("PAE PTE: entry not present"));
848 page_fault(ERROR_NOT_PRESENT, laddr, pl, isWrite, access_type);
850 #if BX_PHY_ADDRESS_WIDTH == 32
851 if (pte & BX_CONST64(0x000fffff00000000)) {
852 BX_PANIC(("PAE PTE 0x%08x%08x: Only 32 bit physical address space is emulated !", GET32H(pte), GET32L(pte)));
854 #endif
855 if (pte & PAGING_PAE_PTE_RESERVED_BITS) {
856 BX_DEBUG(("PAE PTE: reserved bit is set PTE=%08x:%08x", GET32H(pte), GET32L(pte)));
857 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
859 #if BX_SUPPORT_X86_64
860 if (pte & PAGE_DIRECTORY_NX_BIT) {
861 if (! BX_CPU_THIS_PTR efer.get_NXE()) {
862 BX_DEBUG(("PTE: NX bit set when EFER.NXE is disabled"));
863 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
865 if (access_type == CODE_ACCESS) {
866 BX_DEBUG(("PTE: non-executable page fault occured"));
867 nx_fault = 1;
870 #endif
872 combined_access = (pde & pte) & 0x06; // U/S and R/W
873 #if BX_SUPPORT_X86_64
874 if (long_mode()) {
875 combined_access &= (pml4 & pdpe) & 0x06;
877 #endif
879 #if BX_SUPPORT_GLOBAL_PAGES
880 if (BX_CPU_THIS_PTR cr4.get_PGE())
881 combined_access |= (pte & 0x100); // G
882 #endif
884 priv_index =
885 #if BX_CPU_LEVEL >= 4
886 (BX_CPU_THIS_PTR cr0.get_WP() << 4) | // bit 4
887 #endif
888 (pl<<3) | // bit 3
889 (combined_access & 0x06) | // bit 2,1
890 (isWrite); // bit 0
892 if (!priv_check[priv_index] || nx_fault)
893 page_fault(ERROR_PROTECTION, laddr, pl, isWrite, access_type);
895 #if BX_SUPPORT_X86_64
896 if (long_mode()) {
897 // Update PML4 A bit if needed.
898 if (!(pml4 & 0x20)) {
899 pml4 |= 0x20;
900 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pml4_addr, 8, &pml4);
901 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pml4_addr, 8, BX_WRITE, (Bit8u*)(&pml4));
904 #endif
906 // Update PDPE A bit if needed.
907 if (!(pdpe & 0x20)) {
908 pdpe |= 0x20;
909 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pdpe_addr, 8, &pdpe);
910 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pdpe_addr, 8, BX_WRITE, (Bit8u*)(&pdpe));
913 // Update PDE A bit if needed.
914 if (!(pde & 0x20)) {
915 pde |= 0x20;
916 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pde_addr, 8, &pde);
917 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pde_addr, 8, BX_WRITE, (Bit8u*)(&pde));
920 // Update PTE A/D bits if needed.
921 if (((pte & 0x20)==0) || (isWrite && ((pte & 0x40)==0))) {
922 pte |= (0x20 | (isWrite<<6)); // Update A and possibly D bits
923 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pte_addr, 8, &pte);
924 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pte_addr, 8, BX_WRITE, (Bit8u*)(&pte));
927 // Make up the physical page frame address.
928 ppf = (bx_phy_address)(pte & BX_CONST64(0x000ffffffffff000));
930 return ppf;
933 #endif // BX_SUPPORT_PAE
935 /* PSE PDE4M: bits [21:17] */
936 #define PAGING_PSE_PDE4M_RESERVED_BITS \
937 (BX_PHY_ADDRESS_RESERVED_BITS | BX_CONST64(0x003E0000))
939 // Translate a linear address to a physical address
940 bx_phy_address BX_CPU_C::translate_linear(bx_address laddr, unsigned curr_pl, unsigned rw, unsigned access_type)
942 Bit32u combined_access = 0;
943 unsigned priv_index;
945 // note - we assume physical memory < 4gig so for brevity & speed, we'll use
946 // 32 bit entries although cr3 is expanded to 64 bits.
947 bx_phy_address paddress, ppf, poffset = PAGE_OFFSET(laddr);
948 bx_bool isWrite = (rw >= BX_WRITE); // write or r-m-w
949 unsigned pl = (curr_pl == 3);
951 BX_ASSERT(BX_CPU_THIS_PTR cr0.get_PG());
953 InstrTLB_Increment(tlbLookups);
954 InstrTLB_Stats();
956 bx_address lpf = LPFOf(laddr);
957 unsigned TLB_index = BX_TLB_INDEX_OF(lpf, 0);
958 bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[TLB_index];
960 // already looked up TLB for code access
961 if (TLB_LPFOf(tlbEntry->lpf) == lpf)
963 paddress = tlbEntry->ppf | poffset;
965 if (! (tlbEntry->accessBits & ((isWrite<<1) | pl)))
966 return paddress;
968 // The current access does not have permission according to the info
969 // in our TLB cache entry. Re-walk the page tables, in case there is
970 // updated information in the memory image, and let the long path code
971 // generate an exception if one is warranted.
974 BX_DEBUG(("page walk for address 0x" FMT_LIN_ADDRX, laddr));
976 InstrTLB_Increment(tlbMisses);
978 #if BX_SUPPORT_PAE
979 if (BX_CPU_THIS_PTR cr4.get_PAE())
981 ppf = translate_linear_PAE(laddr, combined_access, curr_pl, rw, access_type);
983 else
984 #endif // #if BX_SUPPORT_PAE
986 // CR4.PAE==0 (and EFER.LMA==0)
987 Bit32u pde, pte;
989 bx_phy_address pde_addr = (bx_phy_address) (BX_CPU_THIS_PTR cr3_masked |
990 ((laddr & 0xffc00000) >> 20));
992 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pde_addr, 4, &pde);
993 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pde_addr, 4, BX_READ, (Bit8u*)(&pde));
995 if (!(pde & 0x1)) {
996 BX_DEBUG(("PDE: entry not present"));
997 page_fault(ERROR_NOT_PRESENT, laddr, pl, isWrite, access_type);
1000 #if BX_SUPPORT_LARGE_PAGES
1001 if ((pde & 0x80) && BX_CPU_THIS_PTR cr4.get_PSE())
1003 // Note: when the PSE and PAE flags in CR4 are set, the
1004 // processor generates a PF if the reserved bits are not zero.
1005 if (pde & PAGING_PSE_PDE4M_RESERVED_BITS) {
1006 BX_DEBUG(("PSE PDE4M: reserved bit is set: PDE=0x%08x", pde));
1007 page_fault(ERROR_RESERVED | ERROR_PROTECTION, laddr, pl, isWrite, access_type);
1010 #if BX_PHY_ADDRESS_WIDTH == 32
1011 if (pde & 0x0001e000) {
1012 BX_PANIC(("PSE PDE4M 0x%08x: Only 32 bit physical address space is emulated !", pde));
1014 #endif
1015 // Combined access is just access from the pde (no pte involved).
1016 combined_access = pde & 0x06; // U/S and R/W
1018 #if BX_SUPPORT_GLOBAL_PAGES
1019 if (BX_CPU_THIS_PTR cr4.get_PGE())
1020 combined_access |= pde & 0x100; // {G}
1021 #endif
1023 priv_index =
1024 #if BX_CPU_LEVEL >= 4
1025 (BX_CPU_THIS_PTR cr0.get_WP() << 4) | // bit 4
1026 #endif
1027 (pl<<3) | // bit 3
1028 (combined_access & 0x06) | // bit 2,1
1029 (isWrite); // bit 0
1031 if (!priv_check[priv_index])
1032 page_fault(ERROR_PROTECTION, laddr, pl, isWrite, access_type);
1034 // Update PDE A/D bits if needed.
1035 if (((pde & 0x20)==0) || (isWrite && ((pde & 0x40)==0))) {
1036 pde |= (0x20 | (isWrite<<6)); // Update A and possibly D bits
1037 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pde_addr, 4, &pde);
1038 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pde_addr, 4, BX_WRITE, (Bit8u*)(&pde));
1041 // make up the physical frame number
1042 ppf = (pde & 0xffc00000) | (laddr & 0x003ff000);
1044 else // else normal 4K page...
1045 #endif
1047 // Get page table entry
1048 bx_phy_address pte_addr = (bx_phy_address)((pde & 0xfffff000) | ((laddr & 0x003ff000) >> 10));
1050 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pte_addr, 4, &pte);
1051 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pte_addr, 4, BX_READ, (Bit8u*)(&pte));
1053 if (!(pte & 0x1)) {
1054 BX_DEBUG(("PTE: entry not present"));
1055 page_fault(ERROR_NOT_PRESENT, laddr, pl, isWrite, access_type);
1058 // 386 and 486+ have different behaviour for combining
1059 // privilege from PDE and PTE.
1060 #if BX_CPU_LEVEL == 3
1061 combined_access = (pde | pte) & 0x04; // U/S
1062 combined_access |= (pde & pte) & 0x02; // R/W
1063 #else // 486+
1064 combined_access = (pde & pte) & 0x06; // U/S and R/W
1065 #endif
1067 #if BX_SUPPORT_GLOBAL_PAGES
1068 if (BX_CPU_THIS_PTR cr4.get_PGE())
1069 combined_access |= (pte & 0x100); // G
1070 #endif
1072 priv_index =
1073 #if BX_CPU_LEVEL >= 4
1074 (BX_CPU_THIS_PTR cr0.get_WP() << 4) | // bit 4
1075 #endif
1076 (pl<<3) | // bit 3
1077 (combined_access & 0x06) | // bit 2,1
1078 (isWrite); // bit 0
1080 if (!priv_check[priv_index])
1081 page_fault(ERROR_PROTECTION, laddr, pl, isWrite, access_type);
1083 // Update PDE A bit if needed.
1084 if (!(pde & 0x20)) {
1085 pde |= 0x20;
1086 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pde_addr, 4, &pde);
1087 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pde_addr, 4, BX_WRITE, (Bit8u*)(&pde));
1090 // Update PTE A/D bits if needed.
1091 if (((pte & 0x20)==0) || (isWrite && ((pte & 0x40)==0))) {
1092 pte |= (0x20 | (isWrite<<6)); // Update A and possibly D bits
1093 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, pte_addr, 4, &pte);
1094 BX_DBG_PHY_MEMORY_ACCESS(BX_CPU_ID, pte_addr, 4, BX_WRITE, (Bit8u*)(&pte));
1097 // Make up the physical page frame address.
1098 ppf = pte & 0xfffff000;
1102 // Calculate physical memory address and fill in TLB cache entry
1103 paddress = ppf | poffset;
1105 // direct memory access is NOT allowed by default
1106 tlbEntry->lpf = lpf | TLB_HostPtr;
1107 tlbEntry->ppf = ppf;
1108 tlbEntry->accessBits = 0;
1110 if ((combined_access & 4) == 0) { // System
1111 tlbEntry->accessBits |= TLB_SysOnly;
1112 if (! isWrite)
1113 tlbEntry->accessBits |= TLB_ReadOnly;
1115 else {
1116 // Current operation is a read or a page is read only
1117 // Not efficient handling of system write to user read only page:
1118 // hopefully it is very rare case, optimize later
1119 if (! isWrite || (combined_access & 2) == 0) {
1120 tlbEntry->accessBits |= TLB_ReadOnly;
1124 #if BX_SUPPORT_GLOBAL_PAGES
1125 if (combined_access & 0x100) // Global bit
1126 tlbEntry->accessBits |= TLB_GlobalPage;
1127 #endif
1129 #if BX_SupportGuest2HostTLB
1130 // Attempt to get a host pointer to this physical page. Put that
1131 // pointer in the TLB cache. Note if the request is vetoed, NULL
1132 // will be returned, and it's OK to OR zero in anyways.
1133 tlbEntry->hostPageAddr = (bx_hostpageaddr_t) BX_MEM(0)->getHostMemAddr(BX_CPU_THIS,
1134 A20ADDR(ppf), rw, access_type);
1136 if (tlbEntry->hostPageAddr) {
1137 // All access allowed also via direct pointer
1138 #if BX_X86_DEBUGGER
1139 if (! hwbreakpoint_check(laddr))
1140 #endif
1141 tlbEntry->lpf = lpf; // allow direct access with HostPtr
1143 #endif
1145 return paddress;
1148 #if BX_DEBUGGER || BX_DISASM || BX_INSTRUMENTATION || BX_GDBSTUB
1150 bx_bool BX_CPU_C::dbg_xlate_linear2phy(bx_address laddr, bx_phy_address *phy)
1152 if (BX_CPU_THIS_PTR cr0.get_PG() == 0) {
1153 *phy = (bx_phy_address) laddr;
1154 return 1;
1157 bx_phy_address paddress;
1159 // see if page is in the TLB first
1160 bx_address lpf = LPFOf(laddr);
1161 unsigned TLB_index = BX_TLB_INDEX_OF(lpf, 0);
1162 bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[TLB_index];
1164 if (TLB_LPFOf(tlbEntry->lpf) == lpf) {
1165 paddress = tlbEntry->ppf | PAGE_OFFSET(laddr);
1166 *phy = paddress;
1167 return 1;
1170 bx_phy_address pt_address = BX_CPU_THIS_PTR cr3_masked;
1171 bx_address offset_mask = 0xfff;
1173 #if BX_SUPPORT_PAE
1174 if (BX_CPU_THIS_PTR cr4.get_PAE()) {
1175 int levels = 3;
1176 #if BX_SUPPORT_X86_64
1177 if (long_mode())
1178 levels = 4;
1179 #endif
1180 for (int level = levels - 1; level >= 0; --level) {
1181 Bit64u pte;
1182 pt_address += 8 * ((laddr >> (12 + 9*level)) & 511);
1183 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pt_address, 8, &pte);
1184 if(!(pte & 1))
1185 goto page_fault;
1186 if (pte & BX_PHY_ADDRESS_RESERVED_BITS)
1187 goto page_fault;
1188 pt_address = bx_phy_address(pte & BX_CONST64(0x000ffffffffff000));
1189 if (level == 1 && (pte & 0x80)) { // PSE page
1190 offset_mask = 0x1fffff;
1191 break;
1194 paddress = pt_address + (bx_phy_address)(laddr & offset_mask);
1196 else // not PAE
1197 #endif
1199 for (int level = 1; level >= 0; --level) {
1200 Bit32u pte;
1201 pt_address += 4 * ((laddr >> (12 + 10*level)) & 1023);
1202 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, pt_address, 4, &pte);
1203 if (!(pte & 1))
1204 goto page_fault;
1205 pt_address = pte & 0xfffff000;
1206 if (level == 1 && (pte & 0x80)) { // PSE page
1207 offset_mask = 0x3fffff;
1208 break;
1211 paddress = pt_address + (bx_phy_address)(laddr & offset_mask);
1214 *phy = paddress;
1215 return 1;
1217 page_fault:
1218 *phy = 0;
1219 return 0;
1221 #endif
1223 void BX_CPU_C::access_write_linear(bx_address laddr, unsigned len, unsigned curr_pl, void *data)
1225 #if BX_X86_DEBUGGER
1226 hwbreakpoint_match(laddr, len, BX_WRITE);
1227 #endif
1229 Bit32u pageOffset = PAGE_OFFSET(laddr);
1231 if (BX_CPU_THIS_PTR cr0.get_PG()) {
1232 /* check for reference across multiple pages */
1233 if ((pageOffset + len) <= 4096) {
1234 // Access within single page.
1235 BX_CPU_THIS_PTR address_xlation.paddress1 =
1236 dtranslate_linear(laddr, curr_pl, BX_WRITE);
1237 BX_CPU_THIS_PTR address_xlation.pages = 1;
1239 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, BX_CPU_THIS_PTR address_xlation.paddress1, len, BX_WRITE);
1240 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr, BX_CPU_THIS_PTR address_xlation.paddress1,
1241 len, curr_pl, BX_WRITE, (Bit8u*) data);
1243 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS,
1244 BX_CPU_THIS_PTR address_xlation.paddress1, len, data);
1246 else {
1247 // access across 2 pages
1248 BX_CPU_THIS_PTR address_xlation.paddress1 =
1249 dtranslate_linear(laddr, curr_pl, BX_WRITE);
1250 BX_CPU_THIS_PTR address_xlation.len1 = 4096 - pageOffset;
1251 BX_CPU_THIS_PTR address_xlation.len2 = len -
1252 BX_CPU_THIS_PTR address_xlation.len1;
1253 BX_CPU_THIS_PTR address_xlation.pages = 2;
1254 bx_address laddr2 = laddr + BX_CPU_THIS_PTR address_xlation.len1;
1255 BX_CPU_THIS_PTR address_xlation.paddress2 =
1256 dtranslate_linear(laddr2, curr_pl, BX_WRITE);
1258 #ifdef BX_LITTLE_ENDIAN
1259 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1260 BX_CPU_THIS_PTR address_xlation.paddress1,
1261 BX_CPU_THIS_PTR address_xlation.len1, BX_WRITE);
1262 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1263 BX_CPU_THIS_PTR address_xlation.paddress1,
1264 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1265 BX_WRITE, (Bit8u*) data);
1266 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress1,
1267 BX_CPU_THIS_PTR address_xlation.len1, data);
1268 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1269 BX_CPU_THIS_PTR address_xlation.len2, BX_WRITE);
1270 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1271 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1272 BX_WRITE, ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1273 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress2,
1274 BX_CPU_THIS_PTR address_xlation.len2,
1275 ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1276 #else // BX_BIG_ENDIAN
1277 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1278 BX_CPU_THIS_PTR address_xlation.paddress1,
1279 BX_CPU_THIS_PTR address_xlation.len1, BX_WRITE);
1280 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1281 BX_CPU_THIS_PTR address_xlation.paddress1,
1282 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1283 BX_WRITE, ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1284 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress1,
1285 BX_CPU_THIS_PTR address_xlation.len1,
1286 ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1287 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1288 BX_CPU_THIS_PTR address_xlation.len2, BX_WRITE);
1289 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1290 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1291 BX_WRITE, (Bit8u*) data);
1292 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress2,
1293 BX_CPU_THIS_PTR address_xlation.len2, data);
1294 #endif
1297 else {
1298 // Paging off.
1299 if ((pageOffset + len) <= 4096) {
1300 // Access within single page.
1301 BX_CPU_THIS_PTR address_xlation.paddress1 = (bx_phy_address) laddr;
1302 BX_CPU_THIS_PTR address_xlation.pages = 1;
1303 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, (bx_phy_address) laddr, len, BX_WRITE);
1304 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr, (bx_phy_address) laddr, len,
1305 curr_pl, BX_WRITE, (Bit8u*) data);
1307 #if BX_SupportGuest2HostTLB
1308 // do not replace to the TLB if there is a breakpoint defined
1309 // in the same page
1310 #if BX_X86_DEBUGGER
1311 if (! hwbreakpoint_check(laddr))
1312 #endif
1314 unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 0);
1315 bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
1316 bx_address lpf = LPFOf(laddr);
1318 if (TLB_LPFOf(tlbEntry->lpf) != lpf) {
1319 // We haven't seen this page, or it's been bumped before.
1321 // Request a direct write pointer so we can do either R or W.
1322 bx_hostpageaddr_t hostPageAddr = (bx_hostpageaddr_t)
1323 BX_MEM(0)->getHostMemAddr(BX_CPU_THIS, A20ADDR(lpf), BX_WRITE, DATA_ACCESS);
1325 if (hostPageAddr) {
1326 tlbEntry->lpf = lpf; // Got direct write pointer OK
1327 tlbEntry->ppf = (bx_phy_address) lpf;
1328 tlbEntry->hostPageAddr = hostPageAddr;
1329 // Mark for any operation to succeed.
1330 tlbEntry->accessBits = 0;
1334 #endif
1336 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS, (bx_phy_address) laddr, len, data);
1338 else {
1339 // Access spans two pages.
1340 BX_CPU_THIS_PTR address_xlation.paddress1 = (bx_phy_address) laddr;
1341 BX_CPU_THIS_PTR address_xlation.len1 = 4096 - pageOffset;
1342 BX_CPU_THIS_PTR address_xlation.len2 = len -
1343 BX_CPU_THIS_PTR address_xlation.len1;
1344 BX_CPU_THIS_PTR address_xlation.pages = 2;
1345 bx_address laddr2 = laddr + BX_CPU_THIS_PTR address_xlation.len1;
1346 BX_CPU_THIS_PTR address_xlation.paddress2 = (bx_phy_address) laddr2;
1348 #ifdef BX_LITTLE_ENDIAN
1349 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1350 BX_CPU_THIS_PTR address_xlation.paddress1,
1351 BX_CPU_THIS_PTR address_xlation.len1, BX_WRITE);
1352 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1353 BX_CPU_THIS_PTR address_xlation.paddress1,
1354 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1355 BX_WRITE, (Bit8u*) data);
1356 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS,
1357 BX_CPU_THIS_PTR address_xlation.paddress1,
1358 BX_CPU_THIS_PTR address_xlation.len1, data);
1359 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1360 BX_CPU_THIS_PTR address_xlation.len2, BX_WRITE);
1361 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1362 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1363 BX_WRITE, ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1364 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS,
1365 BX_CPU_THIS_PTR address_xlation.paddress2,
1366 BX_CPU_THIS_PTR address_xlation.len2,
1367 ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1368 #else // BX_BIG_ENDIAN
1369 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1370 BX_CPU_THIS_PTR address_xlation.paddress1,
1371 BX_CPU_THIS_PTR address_xlation.len1, BX_WRITE);
1372 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1373 BX_CPU_THIS_PTR address_xlation.paddress1,
1374 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1375 BX_WRITE, ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1376 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS,
1377 BX_CPU_THIS_PTR address_xlation.paddress1,
1378 BX_CPU_THIS_PTR address_xlation.len1,
1379 ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1380 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1381 BX_CPU_THIS_PTR address_xlation.len2, BX_WRITE);
1382 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1383 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1384 BX_WRITE, (Bit8u*) data);
1385 BX_MEM(0)->writePhysicalPage(BX_CPU_THIS,
1386 BX_CPU_THIS_PTR address_xlation.paddress2,
1387 BX_CPU_THIS_PTR address_xlation.len2, data);
1388 #endif
1393 void BX_CPU_C::access_read_linear(bx_address laddr, unsigned len, unsigned curr_pl, unsigned xlate_rw, void *data)
1395 BX_ASSERT(xlate_rw == BX_READ || xlate_rw == BX_RW);
1397 #if BX_X86_DEBUGGER
1398 hwbreakpoint_match(laddr, len, xlate_rw);
1399 #endif
1401 Bit32u pageOffset = PAGE_OFFSET(laddr);
1403 if (BX_CPU_THIS_PTR cr0.get_PG()) {
1404 /* check for reference across multiple pages */
1405 if ((pageOffset + len) <= 4096) {
1406 // Access within single page.
1407 BX_CPU_THIS_PTR address_xlation.paddress1 =
1408 dtranslate_linear(laddr, curr_pl, xlate_rw);
1409 BX_CPU_THIS_PTR address_xlation.pages = 1;
1410 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS,
1411 BX_CPU_THIS_PTR address_xlation.paddress1, len, data);
1412 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1413 BX_CPU_THIS_PTR address_xlation.paddress1, len, xlate_rw);
1414 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1415 BX_CPU_THIS_PTR address_xlation.paddress1, len, curr_pl,
1416 BX_READ, (Bit8u*) data);
1418 else {
1419 // access across 2 pages
1420 BX_CPU_THIS_PTR address_xlation.paddress1 =
1421 dtranslate_linear(laddr, curr_pl, xlate_rw);
1422 BX_CPU_THIS_PTR address_xlation.len1 = 4096 - pageOffset;
1423 BX_CPU_THIS_PTR address_xlation.len2 = len -
1424 BX_CPU_THIS_PTR address_xlation.len1;
1425 BX_CPU_THIS_PTR address_xlation.pages = 2;
1426 bx_address laddr2 = laddr + BX_CPU_THIS_PTR address_xlation.len1;
1427 BX_CPU_THIS_PTR address_xlation.paddress2 =
1428 dtranslate_linear(laddr2, curr_pl, xlate_rw);
1430 #ifdef BX_LITTLE_ENDIAN
1431 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress1,
1432 BX_CPU_THIS_PTR address_xlation.len1, data);
1433 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1434 BX_CPU_THIS_PTR address_xlation.paddress1,
1435 BX_CPU_THIS_PTR address_xlation.len1, xlate_rw);
1436 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1437 BX_CPU_THIS_PTR address_xlation.paddress1,
1438 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1439 BX_READ, (Bit8u*) data);
1440 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress2,
1441 BX_CPU_THIS_PTR address_xlation.len2,
1442 ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1443 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1444 BX_CPU_THIS_PTR address_xlation.len2, xlate_rw);
1445 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1446 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1447 BX_READ, ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1448 #else // BX_BIG_ENDIAN
1449 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress1,
1450 BX_CPU_THIS_PTR address_xlation.len1,
1451 ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1452 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1453 BX_CPU_THIS_PTR address_xlation.paddress1,
1454 BX_CPU_THIS_PTR address_xlation.len1, xlate_rw);
1455 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1456 BX_CPU_THIS_PTR address_xlation.paddress1,
1457 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1458 BX_READ, ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1459 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, BX_CPU_THIS_PTR address_xlation.paddress2,
1460 BX_CPU_THIS_PTR address_xlation.len2, data);
1461 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1462 BX_CPU_THIS_PTR address_xlation.len2, xlate_rw);
1463 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1464 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1465 BX_READ, (Bit8u*) data);
1466 #endif
1469 else {
1470 // Paging off.
1471 if ((pageOffset + len) <= 4096) {
1472 // Access within single page.
1473 BX_CPU_THIS_PTR address_xlation.paddress1 = (bx_phy_address) laddr;
1474 BX_CPU_THIS_PTR address_xlation.pages = 1;
1475 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr, (bx_phy_address) laddr, len, xlate_rw);
1477 #if BX_SupportGuest2HostTLB
1478 // do not replace to the TLB if there is a breakpoint defined
1479 // in the same page
1480 #if BX_X86_DEBUGGER
1481 if (! hwbreakpoint_check(laddr))
1482 #endif
1484 unsigned tlbIndex = BX_TLB_INDEX_OF(laddr, 0);
1485 bx_TLB_entry *tlbEntry = &BX_CPU_THIS_PTR TLB.entry[tlbIndex];
1486 bx_address lpf = LPFOf(laddr);
1488 if (TLB_LPFOf(tlbEntry->lpf) != lpf) {
1489 // We haven't seen this page, or it's been bumped before.
1491 // Request a direct write pointer so we can do either R or W.
1492 bx_hostpageaddr_t hostPageAddr = (bx_hostpageaddr_t)
1493 BX_MEM(0)->getHostMemAddr(BX_CPU_THIS, A20ADDR(lpf), BX_READ, DATA_ACCESS);
1495 if (hostPageAddr) {
1496 tlbEntry->lpf = lpf; // Got direct read pointer OK.
1497 tlbEntry->ppf = (bx_phy_address) lpf;
1498 tlbEntry->hostPageAddr = hostPageAddr;
1499 // Mark for any following read to succeed.
1500 tlbEntry->accessBits = TLB_ReadOnly;
1504 #endif
1506 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS, (bx_phy_address) laddr, len, data);
1507 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr, (bx_phy_address) laddr, len,
1508 curr_pl, BX_READ, (Bit8u*) data);
1510 else {
1511 // Access spans two pages.
1512 BX_CPU_THIS_PTR address_xlation.paddress1 = (bx_phy_address) laddr;
1513 BX_CPU_THIS_PTR address_xlation.len1 = 4096 - pageOffset;
1514 BX_CPU_THIS_PTR address_xlation.len2 = len -
1515 BX_CPU_THIS_PTR address_xlation.len1;
1516 BX_CPU_THIS_PTR address_xlation.pages = 2;
1517 bx_address laddr2 = laddr + BX_CPU_THIS_PTR address_xlation.len1;
1518 BX_CPU_THIS_PTR address_xlation.paddress2 = (bx_phy_address) laddr2;
1520 #ifdef BX_LITTLE_ENDIAN
1521 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS,
1522 BX_CPU_THIS_PTR address_xlation.paddress1,
1523 BX_CPU_THIS_PTR address_xlation.len1, data);
1524 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1525 BX_CPU_THIS_PTR address_xlation.paddress1,
1526 BX_CPU_THIS_PTR address_xlation.len1, xlate_rw);
1527 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1528 BX_CPU_THIS_PTR address_xlation.paddress1,
1529 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1530 BX_READ, (Bit8u*) data);
1531 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS,
1532 BX_CPU_THIS_PTR address_xlation.paddress2,
1533 BX_CPU_THIS_PTR address_xlation.len2,
1534 ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1535 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1536 BX_CPU_THIS_PTR address_xlation.len2, xlate_rw);
1537 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1538 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1539 BX_READ, ((Bit8u*)data) + BX_CPU_THIS_PTR address_xlation.len1);
1540 #else // BX_BIG_ENDIAN
1541 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS,
1542 BX_CPU_THIS_PTR address_xlation.paddress1,
1543 BX_CPU_THIS_PTR address_xlation.len1,
1544 ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1545 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr,
1546 BX_CPU_THIS_PTR address_xlation.paddress1,
1547 BX_CPU_THIS_PTR address_xlation.len1, xlate_rw);
1548 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr,
1549 BX_CPU_THIS_PTR address_xlation.paddress1,
1550 BX_CPU_THIS_PTR address_xlation.len1, curr_pl,
1551 BX_READ, ((Bit8u*)data) + (len - BX_CPU_THIS_PTR address_xlation.len1));
1552 BX_MEM(0)->readPhysicalPage(BX_CPU_THIS,
1553 BX_CPU_THIS_PTR address_xlation.paddress2,
1554 BX_CPU_THIS_PTR address_xlation.len2, data);
1555 BX_INSTR_LIN_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1556 BX_CPU_THIS_PTR address_xlation.len2, xlate_rw);
1557 BX_DBG_LIN_MEMORY_ACCESS(BX_CPU_ID, laddr2, BX_CPU_THIS_PTR address_xlation.paddress2,
1558 BX_CPU_THIS_PTR address_xlation.len2, curr_pl,
1559 BX_READ, (Bit8u*) data);
1560 #endif