/* This file is part of the program psim.
|
/* This file is part of the program psim.
|
|
|
Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
|
Copyright (C) 1994-1997, Andrew Cagney <cagney@highland.com.au>
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
*/
|
*/
|
|
|
|
|
#ifndef _VM_C_
|
#ifndef _VM_C_
|
#define _VM_C_
|
#define _VM_C_
|
|
|
#if 0
|
#if 0
|
#include "basics.h"
|
#include "basics.h"
|
#include "registers.h"
|
#include "registers.h"
|
#include "device.h"
|
#include "device.h"
|
#include "corefile.h"
|
#include "corefile.h"
|
#include "vm.h"
|
#include "vm.h"
|
#include "interrupts.h"
|
#include "interrupts.h"
|
#include "mon.h"
|
#include "mon.h"
|
#endif
|
#endif
|
|
|
#include "cpu.h"
|
#include "cpu.h"
|
|
|
/* OEA vs VEA
|
/* OEA vs VEA
|
|
|
For the VEA model, the VM layer is almost transparent. It's only
|
For the VEA model, the VM layer is almost transparent. It's only
|
purpose is to maintain separate core_map's for the instruction
|
purpose is to maintain separate core_map's for the instruction
|
and data address spaces. This being so that writes to instruction
|
and data address spaces. This being so that writes to instruction
|
space or execution of a data space is prevented.
|
space or execution of a data space is prevented.
|
|
|
For the OEA model things are more complex. The reason for separate
|
For the OEA model things are more complex. The reason for separate
|
instruction and data models becomes crucial. The OEA model is
|
instruction and data models becomes crucial. The OEA model is
|
built out of three parts. An instruction map, a data map and an
|
built out of three parts. An instruction map, a data map and an
|
underlying structure that provides access to the VM data kept in
|
underlying structure that provides access to the VM data kept in
|
main memory. */
|
main memory. */
|
|
|
|
|
/* OEA data structures:
|
/* OEA data structures:
|
|
|
The OEA model maintains internal data structures that shadow the
|
The OEA model maintains internal data structures that shadow the
|
semantics of the various OEA VM registers (BAT, SR, etc). This
|
semantics of the various OEA VM registers (BAT, SR, etc). This
|
allows a simple efficient model of the VM to be implemented.
|
allows a simple efficient model of the VM to be implemented.
|
|
|
Consistency between OEA registers and this model's internal data
|
Consistency between OEA registers and this model's internal data
|
structures is maintained by updating the structures at
|
structures is maintained by updating the structures at
|
`synchronization' points. Of particular note is that (at the time
|
`synchronization' points. Of particular note is that (at the time
|
of writing) the memory data types for BAT registers are rebuilt
|
of writing) the memory data types for BAT registers are rebuilt
|
when ever the processor moves between problem and system states.
|
when ever the processor moves between problem and system states.
|
|
|
Unpacked values are stored in the OEA so that they correctly align
|
Unpacked values are stored in the OEA so that they correctly align
|
to where they will be needed by the PTE address. */
|
to where they will be needed by the PTE address. */
|
|
|
|
|
/* Protection table:
|
/* Protection table:
|
|
|
Matrix of processor state, type of access and validity */
|
Matrix of processor state, type of access and validity */
|
|
|
typedef enum {
|
typedef enum {
|
om_supervisor_state,
|
om_supervisor_state,
|
om_problem_state,
|
om_problem_state,
|
nr_om_modes
|
nr_om_modes
|
} om_processor_modes;
|
} om_processor_modes;
|
|
|
typedef enum {
|
typedef enum {
|
om_data_read, om_data_write,
|
om_data_read, om_data_write,
|
om_instruction_read, om_access_any,
|
om_instruction_read, om_access_any,
|
nr_om_access_types
|
nr_om_access_types
|
} om_access_types;
|
} om_access_types;
|
|
|
static int om_valid_access[2][4][nr_om_access_types] = {
|
static int om_valid_access[2][4][nr_om_access_types] = {
|
/* read, write, instruction, any */
|
/* read, write, instruction, any */
|
/* K bit == 0 */
|
/* K bit == 0 */
|
{ /*r w i a pp */
|
{ /*r w i a pp */
|
{ 1, 1, 1, 1 }, /* 00 */
|
{ 1, 1, 1, 1 }, /* 00 */
|
{ 1, 1, 1, 1 }, /* 01 */
|
{ 1, 1, 1, 1 }, /* 01 */
|
{ 1, 1, 1, 1 }, /* 10 */
|
{ 1, 1, 1, 1 }, /* 10 */
|
{ 1, 0, 1, 1 }, /* 11 */
|
{ 1, 0, 1, 1 }, /* 11 */
|
},
|
},
|
/* K bit == 1 or P bit valid */
|
/* K bit == 1 or P bit valid */
|
{ /*r w i a pp */
|
{ /*r w i a pp */
|
{ 0, 0, 0, 0 }, /* 00 */
|
{ 0, 0, 0, 0 }, /* 00 */
|
{ 1, 0, 1, 1 }, /* 01 */
|
{ 1, 0, 1, 1 }, /* 01 */
|
{ 1, 1, 1, 1 }, /* 10 */
|
{ 1, 1, 1, 1 }, /* 10 */
|
{ 1, 0, 1, 1 }, /* 11 */
|
{ 1, 0, 1, 1 }, /* 11 */
|
}
|
}
|
};
|
};
|
|
|
|
|
/* Bat translation:
|
/* Bat translation:
|
|
|
The bat data structure only contains information on valid BAT
|
The bat data structure only contains information on valid BAT
|
translations for the current processor mode and type of access. */
|
translations for the current processor mode and type of access. */
|
|
|
typedef struct _om_bat {
|
typedef struct _om_bat {
|
unsigned_word block_effective_page_index;
|
unsigned_word block_effective_page_index;
|
unsigned_word block_effective_page_index_mask;
|
unsigned_word block_effective_page_index_mask;
|
unsigned_word block_length_mask;
|
unsigned_word block_length_mask;
|
unsigned_word block_real_page_number;
|
unsigned_word block_real_page_number;
|
int protection_bits;
|
int protection_bits;
|
} om_bat;
|
} om_bat;
|
|
|
enum _nr_om_bat_registers {
|
enum _nr_om_bat_registers {
|
nr_om_bat_registers = 4
|
nr_om_bat_registers = 4
|
};
|
};
|
|
|
typedef struct _om_bats {
|
typedef struct _om_bats {
|
int nr_valid_bat_registers;
|
int nr_valid_bat_registers;
|
om_bat bat[nr_om_bat_registers];
|
om_bat bat[nr_om_bat_registers];
|
} om_bats;
|
} om_bats;
|
|
|
|
|
/* Segment TLB:
|
/* Segment TLB:
|
|
|
In this model the 32 and 64 bit segment tables are treated in very
|
In this model the 32 and 64 bit segment tables are treated in very
|
similar ways. The 32bit segment registers are treated as a
|
similar ways. The 32bit segment registers are treated as a
|
simplification of the 64bit segment tlb */
|
simplification of the 64bit segment tlb */
|
|
|
enum _om_segment_tlb_constants {
|
enum _om_segment_tlb_constants {
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
sizeof_segment_table_entry_group = 128,
|
sizeof_segment_table_entry_group = 128,
|
sizeof_segment_table_entry = 16,
|
sizeof_segment_table_entry = 16,
|
#endif
|
#endif
|
om_segment_tlb_index_start_bit = 32,
|
om_segment_tlb_index_start_bit = 32,
|
om_segment_tlb_index_stop_bit = 35,
|
om_segment_tlb_index_stop_bit = 35,
|
nr_om_segment_tlb_entries = 16,
|
nr_om_segment_tlb_entries = 16,
|
nr_om_segment_tlb_constants
|
nr_om_segment_tlb_constants
|
};
|
};
|
|
|
typedef struct _om_segment_tlb_entry {
|
typedef struct _om_segment_tlb_entry {
|
int key[nr_om_modes];
|
int key[nr_om_modes];
|
om_access_types invalid_access; /* set to instruction if no_execute bit */
|
om_access_types invalid_access; /* set to instruction if no_execute bit */
|
unsigned_word masked_virtual_segment_id; /* aligned ready for pte group addr */
|
unsigned_word masked_virtual_segment_id; /* aligned ready for pte group addr */
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
int is_valid;
|
int is_valid;
|
unsigned_word masked_effective_segment_id;
|
unsigned_word masked_effective_segment_id;
|
#endif
|
#endif
|
} om_segment_tlb_entry;
|
} om_segment_tlb_entry;
|
|
|
typedef struct _om_segment_tlb {
|
typedef struct _om_segment_tlb {
|
om_segment_tlb_entry entry[nr_om_segment_tlb_entries];
|
om_segment_tlb_entry entry[nr_om_segment_tlb_entries];
|
} om_segment_tlb;
|
} om_segment_tlb;
|
|
|
|
|
/* Page TLB:
|
/* Page TLB:
|
|
|
This OEA model includes a small direct map Page TLB. The tlb is to
|
This OEA model includes a small direct map Page TLB. The tlb is to
|
cut down on the need for the OEA to perform walks of the page hash
|
cut down on the need for the OEA to perform walks of the page hash
|
table. */
|
table. */
|
|
|
enum _om_page_tlb_constants {
|
enum _om_page_tlb_constants {
|
om_page_tlb_index_start_bit = 46,
|
om_page_tlb_index_start_bit = 46,
|
om_page_tlb_index_stop_bit = 51,
|
om_page_tlb_index_stop_bit = 51,
|
nr_om_page_tlb_entries = 64,
|
nr_om_page_tlb_entries = 64,
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
sizeof_pte_group = 128,
|
sizeof_pte_group = 128,
|
sizeof_pte = 16,
|
sizeof_pte = 16,
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
sizeof_pte_group = 64,
|
sizeof_pte_group = 64,
|
sizeof_pte = 8,
|
sizeof_pte = 8,
|
#endif
|
#endif
|
nr_om_page_tlb_constants
|
nr_om_page_tlb_constants
|
};
|
};
|
|
|
typedef struct _om_page_tlb_entry {
|
typedef struct _om_page_tlb_entry {
|
int protection;
|
int protection;
|
int changed;
|
int changed;
|
unsigned_word real_address_of_pte_1;
|
unsigned_word real_address_of_pte_1;
|
unsigned_word masked_virtual_segment_id;
|
unsigned_word masked_virtual_segment_id;
|
unsigned_word masked_page;
|
unsigned_word masked_page;
|
unsigned_word masked_real_page_number;
|
unsigned_word masked_real_page_number;
|
} om_page_tlb_entry;
|
} om_page_tlb_entry;
|
|
|
typedef struct _om_page_tlb {
|
typedef struct _om_page_tlb {
|
om_page_tlb_entry entry[nr_om_page_tlb_entries];
|
om_page_tlb_entry entry[nr_om_page_tlb_entries];
|
} om_page_tlb;
|
} om_page_tlb;
|
|
|
|
|
/* memory translation:
|
/* memory translation:
|
|
|
OEA memory translation possibly involves BAT, SR, TLB and HTAB
|
OEA memory translation possibly involves BAT, SR, TLB and HTAB
|
information*/
|
information*/
|
|
|
typedef struct _om_map {
|
typedef struct _om_map {
|
|
|
/* local cache of register values */
|
/* local cache of register values */
|
int is_relocate;
|
int is_relocate;
|
int is_problem_state;
|
int is_problem_state;
|
|
|
/* block address translation */
|
/* block address translation */
|
om_bats *bat_registers;
|
om_bats *bat_registers;
|
|
|
/* failing that, translate ea to va using segment tlb */
|
/* failing that, translate ea to va using segment tlb */
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
unsigned_word real_address_of_segment_table;
|
unsigned_word real_address_of_segment_table;
|
#endif
|
#endif
|
om_segment_tlb *segment_tlb;
|
om_segment_tlb *segment_tlb;
|
|
|
/* then va to ra using hashed page table and tlb */
|
/* then va to ra using hashed page table and tlb */
|
unsigned_word real_address_of_page_table;
|
unsigned_word real_address_of_page_table;
|
unsigned_word page_table_hash_mask;
|
unsigned_word page_table_hash_mask;
|
om_page_tlb *page_tlb;
|
om_page_tlb *page_tlb;
|
|
|
/* physical memory for fetching page table entries */
|
/* physical memory for fetching page table entries */
|
core_map *physical;
|
core_map *physical;
|
|
|
/* address xor for PPC endian */
|
/* address xor for PPC endian */
|
unsigned xor[WITH_XOR_ENDIAN];
|
unsigned xor[WITH_XOR_ENDIAN];
|
|
|
} om_map;
|
} om_map;
|
|
|
|
|
/* VM objects:
|
/* VM objects:
|
|
|
External objects defined by vm.h */
|
External objects defined by vm.h */
|
|
|
struct _vm_instruction_map {
|
struct _vm_instruction_map {
|
/* real memory for last part */
|
/* real memory for last part */
|
core_map *code;
|
core_map *code;
|
/* translate effective to real */
|
/* translate effective to real */
|
om_map translation;
|
om_map translation;
|
};
|
};
|
|
|
struct _vm_data_map {
|
struct _vm_data_map {
|
/* translate effective to real */
|
/* translate effective to real */
|
om_map translation;
|
om_map translation;
|
/* real memory for translated address */
|
/* real memory for translated address */
|
core_map *read;
|
core_map *read;
|
core_map *write;
|
core_map *write;
|
};
|
};
|
|
|
|
|
/* VM:
|
/* VM:
|
|
|
Underlying memory object. For the VEA this is just the
|
Underlying memory object. For the VEA this is just the
|
core_map. For OEA it is the instruction and data memory
|
core_map. For OEA it is the instruction and data memory
|
translation's */
|
translation's */
|
|
|
struct _vm {
|
struct _vm {
|
|
|
/* OEA: base address registers */
|
/* OEA: base address registers */
|
om_bats ibats;
|
om_bats ibats;
|
om_bats dbats;
|
om_bats dbats;
|
|
|
/* OEA: segment registers */
|
/* OEA: segment registers */
|
om_segment_tlb segment_tlb;
|
om_segment_tlb segment_tlb;
|
|
|
/* OEA: translation lookaside buffers */
|
/* OEA: translation lookaside buffers */
|
om_page_tlb instruction_tlb;
|
om_page_tlb instruction_tlb;
|
om_page_tlb data_tlb;
|
om_page_tlb data_tlb;
|
|
|
/* real memory */
|
/* real memory */
|
core *physical;
|
core *physical;
|
|
|
/* memory maps */
|
/* memory maps */
|
vm_instruction_map instruction_map;
|
vm_instruction_map instruction_map;
|
vm_data_map data_map;
|
vm_data_map data_map;
|
|
|
};
|
};
|
|
|
|
|
/* OEA Support procedures */
|
/* OEA Support procedures */
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_segment_tlb_index(unsigned_word ea)
|
om_segment_tlb_index(unsigned_word ea)
|
{
|
{
|
unsigned_word index = EXTRACTED(ea,
|
unsigned_word index = EXTRACTED(ea,
|
om_segment_tlb_index_start_bit,
|
om_segment_tlb_index_start_bit,
|
om_segment_tlb_index_stop_bit);
|
om_segment_tlb_index_stop_bit);
|
return index;
|
return index;
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_page_tlb_index(unsigned_word ea)
|
om_page_tlb_index(unsigned_word ea)
|
{
|
{
|
unsigned_word index = EXTRACTED(ea,
|
unsigned_word index = EXTRACTED(ea,
|
om_page_tlb_index_start_bit,
|
om_page_tlb_index_start_bit,
|
om_page_tlb_index_stop_bit);
|
om_page_tlb_index_stop_bit);
|
return index;
|
return index;
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_hash_page(unsigned_word masked_vsid,
|
om_hash_page(unsigned_word masked_vsid,
|
unsigned_word ea)
|
unsigned_word ea)
|
{
|
{
|
unsigned_word extracted_ea = EXTRACTED(ea, 36, 51);
|
unsigned_word extracted_ea = EXTRACTED(ea, 36, 51);
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
unsigned_word masked_ea = INSERTED32(extracted_ea, 7, 31-6);
|
unsigned_word masked_ea = INSERTED32(extracted_ea, 7, 31-6);
|
unsigned_word hash = masked_vsid ^ masked_ea;
|
unsigned_word hash = masked_vsid ^ masked_ea;
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
unsigned_word masked_ea = INSERTED64(extracted_ea, 18, 63-7);
|
unsigned_word masked_ea = INSERTED64(extracted_ea, 18, 63-7);
|
unsigned_word hash = masked_vsid ^ masked_ea;
|
unsigned_word hash = masked_vsid ^ masked_ea;
|
#endif
|
#endif
|
TRACE(trace_vm, ("ea=0x%lx - masked-vsid=0x%lx masked-ea=0x%lx hash=0x%lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - masked-vsid=0x%lx masked-ea=0x%lx hash=0x%lx\n",
|
(unsigned long)ea,
|
(unsigned long)ea,
|
(unsigned long)masked_vsid,
|
(unsigned long)masked_vsid,
|
(unsigned long)masked_ea,
|
(unsigned long)masked_ea,
|
(unsigned long)hash));
|
(unsigned long)hash));
|
return hash;
|
return hash;
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_pte_0_api(unsigned_word pte_0)
|
om_pte_0_api(unsigned_word pte_0)
|
{
|
{
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
return EXTRACTED32(pte_0, 26, 31);
|
return EXTRACTED32(pte_0, 26, 31);
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
return EXTRACTED64(pte_0, 52, 56);
|
return EXTRACTED64(pte_0, 52, 56);
|
#endif
|
#endif
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_pte_0_hash(unsigned_word pte_0)
|
om_pte_0_hash(unsigned_word pte_0)
|
{
|
{
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
return EXTRACTED32(pte_0, 25, 25);
|
return EXTRACTED32(pte_0, 25, 25);
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
return EXTRACTED64(pte_0, 62, 62);
|
return EXTRACTED64(pte_0, 62, 62);
|
#endif
|
#endif
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(int)
|
(int)
|
om_pte_0_valid(unsigned_word pte_0)
|
om_pte_0_valid(unsigned_word pte_0)
|
{
|
{
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
return MASKED32(pte_0, 0, 0) != 0;
|
return MASKED32(pte_0, 0, 0) != 0;
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
return MASKED64(pte_0, 63, 63) != 0;
|
return MASKED64(pte_0, 63, 63) != 0;
|
#endif
|
#endif
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_ea_masked_page(unsigned_word ea)
|
om_ea_masked_page(unsigned_word ea)
|
{
|
{
|
return MASKED(ea, 36, 51);
|
return MASKED(ea, 36, 51);
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_ea_masked_byte(unsigned_word ea)
|
om_ea_masked_byte(unsigned_word ea)
|
{
|
{
|
return MASKED(ea, 52, 63);
|
return MASKED(ea, 52, 63);
|
}
|
}
|
|
|
/* return the VSID aligned for pte group addr */
|
/* return the VSID aligned for pte group addr */
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_pte_0_masked_vsid(unsigned_word pte_0)
|
om_pte_0_masked_vsid(unsigned_word pte_0)
|
{
|
{
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
return INSERTED32(EXTRACTED32(pte_0, 1, 24), 31-6-24+1, 31-6);
|
return INSERTED32(EXTRACTED32(pte_0, 1, 24), 31-6-24+1, 31-6);
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
return INSERTED64(EXTRACTED64(pte_0, 0, 51), 63-7-52+1, 63-7);
|
return INSERTED64(EXTRACTED64(pte_0, 0, 51), 63-7-52+1, 63-7);
|
#endif
|
#endif
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_pte_1_pp(unsigned_word pte_1)
|
om_pte_1_pp(unsigned_word pte_1)
|
{
|
{
|
return MASKED(pte_1, 62, 63); /*PP*/
|
return MASKED(pte_1, 62, 63); /*PP*/
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(int)
|
(int)
|
om_pte_1_referenced(unsigned_word pte_1)
|
om_pte_1_referenced(unsigned_word pte_1)
|
{
|
{
|
return EXTRACTED(pte_1, 55, 55);
|
return EXTRACTED(pte_1, 55, 55);
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(int)
|
(int)
|
om_pte_1_changed(unsigned_word pte_1)
|
om_pte_1_changed(unsigned_word pte_1)
|
{
|
{
|
return EXTRACTED(pte_1, 56, 56);
|
return EXTRACTED(pte_1, 56, 56);
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(int)
|
(int)
|
om_pte_1_masked_rpn(unsigned_word pte_1)
|
om_pte_1_masked_rpn(unsigned_word pte_1)
|
{
|
{
|
return MASKED(pte_1, 0, 51); /*RPN*/
|
return MASKED(pte_1, 0, 51); /*RPN*/
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_ea_api(unsigned_word ea)
|
om_ea_api(unsigned_word ea)
|
{
|
{
|
return EXTRACTED(ea, 36, 41);
|
return EXTRACTED(ea, 36, 41);
|
}
|
}
|
|
|
|
|
/* Page and Segment table read/write operators, these need to still
|
/* Page and Segment table read/write operators, these need to still
|
account for the PPC's XOR operation */
|
account for the PPC's XOR operation */
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_read_word(om_map *map,
|
om_read_word(om_map *map,
|
unsigned_word ra,
|
unsigned_word ra,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
if (WITH_XOR_ENDIAN)
|
if (WITH_XOR_ENDIAN)
|
ra ^= map->xor[sizeof(instruction_word) - 1];
|
ra ^= map->xor[sizeof(instruction_word) - 1];
|
return core_map_read_word(map->physical, ra, processor, cia);
|
return core_map_read_word(map->physical, ra, processor, cia);
|
}
|
}
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(void)
|
(void)
|
om_write_word(om_map *map,
|
om_write_word(om_map *map,
|
unsigned_word ra,
|
unsigned_word ra,
|
unsigned_word val,
|
unsigned_word val,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
if (WITH_XOR_ENDIAN)
|
if (WITH_XOR_ENDIAN)
|
ra ^= map->xor[sizeof(instruction_word) - 1];
|
ra ^= map->xor[sizeof(instruction_word) - 1];
|
core_map_write_word(map->physical, ra, val, processor, cia);
|
core_map_write_word(map->physical, ra, val, processor, cia);
|
}
|
}
|
|
|
|
|
/* Bring things into existance */
|
/* Bring things into existance */
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(vm *)
|
(vm *)
|
vm_create(core *physical)
|
vm_create(core *physical)
|
{
|
{
|
vm *virtual;
|
vm *virtual;
|
|
|
/* internal checks */
|
/* internal checks */
|
if (nr_om_segment_tlb_entries
|
if (nr_om_segment_tlb_entries
|
!= (1 << (om_segment_tlb_index_stop_bit
|
!= (1 << (om_segment_tlb_index_stop_bit
|
- om_segment_tlb_index_start_bit + 1)))
|
- om_segment_tlb_index_start_bit + 1)))
|
error("internal error - vm_create - problem with om_segment constants\n");
|
error("internal error - vm_create - problem with om_segment constants\n");
|
if (nr_om_page_tlb_entries
|
if (nr_om_page_tlb_entries
|
!= (1 << (om_page_tlb_index_stop_bit
|
!= (1 << (om_page_tlb_index_stop_bit
|
- om_page_tlb_index_start_bit + 1)))
|
- om_page_tlb_index_start_bit + 1)))
|
error("internal error - vm_create - problem with om_page constants\n");
|
error("internal error - vm_create - problem with om_page constants\n");
|
|
|
/* create the new vm register file */
|
/* create the new vm register file */
|
virtual = ZALLOC(vm);
|
virtual = ZALLOC(vm);
|
|
|
/* set up core */
|
/* set up core */
|
virtual->physical = physical;
|
virtual->physical = physical;
|
|
|
/* set up the address decoders */
|
/* set up the address decoders */
|
virtual->instruction_map.translation.bat_registers = &virtual->ibats;
|
virtual->instruction_map.translation.bat_registers = &virtual->ibats;
|
virtual->instruction_map.translation.segment_tlb = &virtual->segment_tlb;
|
virtual->instruction_map.translation.segment_tlb = &virtual->segment_tlb;
|
virtual->instruction_map.translation.page_tlb = &virtual->instruction_tlb;
|
virtual->instruction_map.translation.page_tlb = &virtual->instruction_tlb;
|
virtual->instruction_map.translation.is_relocate = 0;
|
virtual->instruction_map.translation.is_relocate = 0;
|
virtual->instruction_map.translation.is_problem_state = 0;
|
virtual->instruction_map.translation.is_problem_state = 0;
|
virtual->instruction_map.translation.physical = core_readable(physical);
|
virtual->instruction_map.translation.physical = core_readable(physical);
|
virtual->instruction_map.code = core_readable(physical);
|
virtual->instruction_map.code = core_readable(physical);
|
|
|
virtual->data_map.translation.bat_registers = &virtual->dbats;
|
virtual->data_map.translation.bat_registers = &virtual->dbats;
|
virtual->data_map.translation.segment_tlb = &virtual->segment_tlb;
|
virtual->data_map.translation.segment_tlb = &virtual->segment_tlb;
|
virtual->data_map.translation.page_tlb = &virtual->data_tlb;
|
virtual->data_map.translation.page_tlb = &virtual->data_tlb;
|
virtual->data_map.translation.is_relocate = 0;
|
virtual->data_map.translation.is_relocate = 0;
|
virtual->data_map.translation.is_problem_state = 0;
|
virtual->data_map.translation.is_problem_state = 0;
|
virtual->data_map.translation.physical = core_readable(physical);
|
virtual->data_map.translation.physical = core_readable(physical);
|
virtual->data_map.read = core_readable(physical);
|
virtual->data_map.read = core_readable(physical);
|
virtual->data_map.write = core_writeable(physical);
|
virtual->data_map.write = core_writeable(physical);
|
|
|
return virtual;
|
return virtual;
|
}
|
}
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(om_bat *)
|
(om_bat *)
|
om_effective_to_bat(om_map *map,
|
om_effective_to_bat(om_map *map,
|
unsigned_word ea)
|
unsigned_word ea)
|
{
|
{
|
int curr_bat = 0;
|
int curr_bat = 0;
|
om_bats *bats = map->bat_registers;
|
om_bats *bats = map->bat_registers;
|
int nr_bats = bats->nr_valid_bat_registers;
|
int nr_bats = bats->nr_valid_bat_registers;
|
|
|
for (curr_bat = 0; curr_bat < nr_bats; curr_bat++) {
|
for (curr_bat = 0; curr_bat < nr_bats; curr_bat++) {
|
om_bat *bat = bats->bat + curr_bat;
|
om_bat *bat = bats->bat + curr_bat;
|
if ((ea & bat->block_effective_page_index_mask)
|
if ((ea & bat->block_effective_page_index_mask)
|
!= bat->block_effective_page_index)
|
!= bat->block_effective_page_index)
|
continue;
|
continue;
|
return bat;
|
return bat;
|
}
|
}
|
|
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(om_segment_tlb_entry *)
|
(om_segment_tlb_entry *)
|
om_effective_to_virtual(om_map *map,
|
om_effective_to_virtual(om_map *map,
|
unsigned_word ea,
|
unsigned_word ea,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
/* first try the segment tlb */
|
/* first try the segment tlb */
|
om_segment_tlb_entry *segment_tlb_entry = (map->segment_tlb->entry
|
om_segment_tlb_entry *segment_tlb_entry = (map->segment_tlb->entry
|
+ om_segment_tlb_index(ea));
|
+ om_segment_tlb_index(ea));
|
|
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
TRACE(trace_vm, ("ea=0x%lx - sr[%ld] - masked-vsid=0x%lx va=0x%lx%07lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - sr[%ld] - masked-vsid=0x%lx va=0x%lx%07lx\n",
|
(unsigned long)ea,
|
(unsigned long)ea,
|
(long)om_segment_tlb_index(ea),
|
(long)om_segment_tlb_index(ea),
|
(unsigned long)segment_tlb_entry->masked_virtual_segment_id,
|
(unsigned long)segment_tlb_entry->masked_virtual_segment_id,
|
(unsigned long)EXTRACTED32(segment_tlb_entry->masked_virtual_segment_id, 31-6-24+1, 31-6),
|
(unsigned long)EXTRACTED32(segment_tlb_entry->masked_virtual_segment_id, 31-6-24+1, 31-6),
|
(unsigned long)EXTRACTED32(ea, 4, 31)));
|
(unsigned long)EXTRACTED32(ea, 4, 31)));
|
return segment_tlb_entry;
|
return segment_tlb_entry;
|
#endif
|
#endif
|
|
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
if (segment_tlb_entry->is_valid
|
if (segment_tlb_entry->is_valid
|
&& (segment_tlb_entry->masked_effective_segment_id == MASKED(ea, 0, 35))) {
|
&& (segment_tlb_entry->masked_effective_segment_id == MASKED(ea, 0, 35))) {
|
error("fixme - is there a need to update any bits\n");
|
error("fixme - is there a need to update any bits\n");
|
return segment_tlb_entry;
|
return segment_tlb_entry;
|
}
|
}
|
|
|
/* drats, segment tlb missed */
|
/* drats, segment tlb missed */
|
{
|
{
|
unsigned_word segment_id_hash = ea;
|
unsigned_word segment_id_hash = ea;
|
int current_hash = 0;
|
int current_hash = 0;
|
for (current_hash = 0; current_hash < 2; current_hash += 1) {
|
for (current_hash = 0; current_hash < 2; current_hash += 1) {
|
unsigned_word segment_table_entry_group =
|
unsigned_word segment_table_entry_group =
|
(map->real_address_of_segment_table
|
(map->real_address_of_segment_table
|
| (MASKED64(segment_id_hash, 31, 35) >> (56-35)));
|
| (MASKED64(segment_id_hash, 31, 35) >> (56-35)));
|
unsigned_word segment_table_entry;
|
unsigned_word segment_table_entry;
|
for (segment_table_entry = segment_table_entry_group;
|
for (segment_table_entry = segment_table_entry_group;
|
segment_table_entry < (segment_table_entry_group
|
segment_table_entry < (segment_table_entry_group
|
+ sizeof_segment_table_entry_group);
|
+ sizeof_segment_table_entry_group);
|
segment_table_entry += sizeof_segment_table_entry) {
|
segment_table_entry += sizeof_segment_table_entry) {
|
/* byte order? */
|
/* byte order? */
|
unsigned_word segment_table_entry_dword_0 =
|
unsigned_word segment_table_entry_dword_0 =
|
om_read_word(map->physical, segment_table_entry, processor, cia);
|
om_read_word(map->physical, segment_table_entry, processor, cia);
|
unsigned_word segment_table_entry_dword_1 =
|
unsigned_word segment_table_entry_dword_1 =
|
om_read_word(map->physical, segment_table_entry + 8,
|
om_read_word(map->physical, segment_table_entry + 8,
|
processor, cia);
|
processor, cia);
|
int is_valid = MASKED64(segment_table_entry_dword_0, 56, 56) != 0;
|
int is_valid = MASKED64(segment_table_entry_dword_0, 56, 56) != 0;
|
unsigned_word masked_effective_segment_id =
|
unsigned_word masked_effective_segment_id =
|
MASKED64(segment_table_entry_dword_0, 0, 35);
|
MASKED64(segment_table_entry_dword_0, 0, 35);
|
if (is_valid && masked_effective_segment_id == MASKED64(ea, 0, 35)) {
|
if (is_valid && masked_effective_segment_id == MASKED64(ea, 0, 35)) {
|
/* don't permit some things */
|
/* don't permit some things */
|
if (MASKED64(segment_table_entry_dword_0, 57, 57))
|
if (MASKED64(segment_table_entry_dword_0, 57, 57))
|
error("om_effective_to_virtual() - T=1 in STE not supported\n");
|
error("om_effective_to_virtual() - T=1 in STE not supported\n");
|
/* update segment tlb */
|
/* update segment tlb */
|
segment_tlb_entry->is_valid = is_valid;
|
segment_tlb_entry->is_valid = is_valid;
|
segment_tlb_entry->masked_effective_segment_id =
|
segment_tlb_entry->masked_effective_segment_id =
|
masked_effective_segment_id;
|
masked_effective_segment_id;
|
segment_tlb_entry->key[om_supervisor_state] =
|
segment_tlb_entry->key[om_supervisor_state] =
|
EXTRACTED64(segment_table_entry_dword_0, 58, 58);
|
EXTRACTED64(segment_table_entry_dword_0, 58, 58);
|
segment_tlb_entry->key[om_problem_state] =
|
segment_tlb_entry->key[om_problem_state] =
|
EXTRACTED64(segment_table_entry_dword_0, 59, 59);
|
EXTRACTED64(segment_table_entry_dword_0, 59, 59);
|
segment_tlb_entry->invalid_access =
|
segment_tlb_entry->invalid_access =
|
(MASKED64(segment_table_entry_dword_0, 60, 60)
|
(MASKED64(segment_table_entry_dword_0, 60, 60)
|
? om_instruction_read
|
? om_instruction_read
|
: om_access_any);
|
: om_access_any);
|
segment_tlb_entry->masked_virtual_segment_id =
|
segment_tlb_entry->masked_virtual_segment_id =
|
INSERTED64(EXTRACTED64(segment_table_entry_dword_1, 0, 51),
|
INSERTED64(EXTRACTED64(segment_table_entry_dword_1, 0, 51),
|
18-13, 63-7); /* aligned ready for pte group addr */
|
18-13, 63-7); /* aligned ready for pte group addr */
|
return segment_tlb_entry;
|
return segment_tlb_entry;
|
}
|
}
|
}
|
}
|
segment_id_hash = ~segment_id_hash;
|
segment_id_hash = ~segment_id_hash;
|
}
|
}
|
}
|
}
|
return NULL;
|
return NULL;
|
#endif
|
#endif
|
}
|
}
|
|
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(om_page_tlb_entry *)
|
(om_page_tlb_entry *)
|
om_virtual_to_real(om_map *map,
|
om_virtual_to_real(om_map *map,
|
unsigned_word ea,
|
unsigned_word ea,
|
om_segment_tlb_entry *segment_tlb_entry,
|
om_segment_tlb_entry *segment_tlb_entry,
|
om_access_types access,
|
om_access_types access,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
om_page_tlb_entry *page_tlb_entry = (map->page_tlb->entry
|
om_page_tlb_entry *page_tlb_entry = (map->page_tlb->entry
|
+ om_page_tlb_index(ea));
|
+ om_page_tlb_index(ea));
|
|
|
/* is it a tlb hit? */
|
/* is it a tlb hit? */
|
if ((page_tlb_entry->masked_virtual_segment_id
|
if ((page_tlb_entry->masked_virtual_segment_id
|
== segment_tlb_entry->masked_virtual_segment_id)
|
== segment_tlb_entry->masked_virtual_segment_id)
|
&& (page_tlb_entry->masked_page
|
&& (page_tlb_entry->masked_page
|
== om_ea_masked_page(ea))) {
|
== om_ea_masked_page(ea))) {
|
TRACE(trace_vm, ("ea=0x%lx - tlb hit - tlb=0x%lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - tlb hit - tlb=0x%lx\n",
|
(long)ea, (long)page_tlb_entry));
|
(long)ea, (long)page_tlb_entry));
|
return page_tlb_entry;
|
return page_tlb_entry;
|
}
|
}
|
|
|
/* drats, it is a tlb miss */
|
/* drats, it is a tlb miss */
|
{
|
{
|
unsigned_word page_hash =
|
unsigned_word page_hash =
|
om_hash_page(segment_tlb_entry->masked_virtual_segment_id, ea);
|
om_hash_page(segment_tlb_entry->masked_virtual_segment_id, ea);
|
int current_hash;
|
int current_hash;
|
for (current_hash = 0; current_hash < 2; current_hash += 1) {
|
for (current_hash = 0; current_hash < 2; current_hash += 1) {
|
unsigned_word real_address_of_pte_group =
|
unsigned_word real_address_of_pte_group =
|
(map->real_address_of_page_table
|
(map->real_address_of_page_table
|
| (page_hash & map->page_table_hash_mask));
|
| (page_hash & map->page_table_hash_mask));
|
unsigned_word real_address_of_pte_0;
|
unsigned_word real_address_of_pte_0;
|
TRACE(trace_vm,
|
TRACE(trace_vm,
|
("ea=0x%lx - htab search %d - htab=0x%lx hash=0x%lx mask=0x%lx pteg=0x%lx\n",
|
("ea=0x%lx - htab search %d - htab=0x%lx hash=0x%lx mask=0x%lx pteg=0x%lx\n",
|
(long)ea, current_hash,
|
(long)ea, current_hash,
|
map->real_address_of_page_table,
|
map->real_address_of_page_table,
|
page_hash,
|
page_hash,
|
map->page_table_hash_mask,
|
map->page_table_hash_mask,
|
(long)real_address_of_pte_group));
|
(long)real_address_of_pte_group));
|
for (real_address_of_pte_0 = real_address_of_pte_group;
|
for (real_address_of_pte_0 = real_address_of_pte_group;
|
real_address_of_pte_0 < (real_address_of_pte_group
|
real_address_of_pte_0 < (real_address_of_pte_group
|
+ sizeof_pte_group);
|
+ sizeof_pte_group);
|
real_address_of_pte_0 += sizeof_pte) {
|
real_address_of_pte_0 += sizeof_pte) {
|
unsigned_word pte_0 = om_read_word(map,
|
unsigned_word pte_0 = om_read_word(map,
|
real_address_of_pte_0,
|
real_address_of_pte_0,
|
processor, cia);
|
processor, cia);
|
/* did we hit? */
|
/* did we hit? */
|
if (om_pte_0_valid(pte_0)
|
if (om_pte_0_valid(pte_0)
|
&& (current_hash == om_pte_0_hash(pte_0))
|
&& (current_hash == om_pte_0_hash(pte_0))
|
&& (segment_tlb_entry->masked_virtual_segment_id
|
&& (segment_tlb_entry->masked_virtual_segment_id
|
== om_pte_0_masked_vsid(pte_0))
|
== om_pte_0_masked_vsid(pte_0))
|
&& (om_ea_api(ea) == om_pte_0_api(pte_0))) {
|
&& (om_ea_api(ea) == om_pte_0_api(pte_0))) {
|
unsigned_word real_address_of_pte_1 = (real_address_of_pte_0
|
unsigned_word real_address_of_pte_1 = (real_address_of_pte_0
|
+ sizeof_pte / 2);
|
+ sizeof_pte / 2);
|
unsigned_word pte_1 = om_read_word(map,
|
unsigned_word pte_1 = om_read_word(map,
|
real_address_of_pte_1,
|
real_address_of_pte_1,
|
processor, cia);
|
processor, cia);
|
page_tlb_entry->protection = om_pte_1_pp(pte_1);
|
page_tlb_entry->protection = om_pte_1_pp(pte_1);
|
page_tlb_entry->changed = om_pte_1_changed(pte_1);
|
page_tlb_entry->changed = om_pte_1_changed(pte_1);
|
page_tlb_entry->masked_virtual_segment_id = segment_tlb_entry->masked_virtual_segment_id;
|
page_tlb_entry->masked_virtual_segment_id = segment_tlb_entry->masked_virtual_segment_id;
|
page_tlb_entry->masked_page = om_ea_masked_page(ea);
|
page_tlb_entry->masked_page = om_ea_masked_page(ea);
|
page_tlb_entry->masked_real_page_number = om_pte_1_masked_rpn(pte_1);
|
page_tlb_entry->masked_real_page_number = om_pte_1_masked_rpn(pte_1);
|
page_tlb_entry->real_address_of_pte_1 = real_address_of_pte_1;
|
page_tlb_entry->real_address_of_pte_1 = real_address_of_pte_1;
|
if (!om_pte_1_referenced(pte_1)) {
|
if (!om_pte_1_referenced(pte_1)) {
|
om_write_word(map,
|
om_write_word(map,
|
real_address_of_pte_1,
|
real_address_of_pte_1,
|
pte_1 | BIT(55),
|
pte_1 | BIT(55),
|
processor, cia);
|
processor, cia);
|
TRACE(trace_vm,
|
TRACE(trace_vm,
|
("ea=0x%lx - htab hit - set ref - tlb=0x%lx &pte1=0x%lx\n",
|
("ea=0x%lx - htab hit - set ref - tlb=0x%lx &pte1=0x%lx\n",
|
(long)ea, (long)page_tlb_entry, (long)real_address_of_pte_1));
|
(long)ea, (long)page_tlb_entry, (long)real_address_of_pte_1));
|
}
|
}
|
else {
|
else {
|
TRACE(trace_vm,
|
TRACE(trace_vm,
|
("ea=0x%lx - htab hit - tlb=0x%lx &pte1=0x%lx\n",
|
("ea=0x%lx - htab hit - tlb=0x%lx &pte1=0x%lx\n",
|
(long)ea, (long)page_tlb_entry, (long)real_address_of_pte_1));
|
(long)ea, (long)page_tlb_entry, (long)real_address_of_pte_1));
|
}
|
}
|
return page_tlb_entry;
|
return page_tlb_entry;
|
}
|
}
|
}
|
}
|
page_hash = ~page_hash; /*???*/
|
page_hash = ~page_hash; /*???*/
|
}
|
}
|
}
|
}
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(void)
|
(void)
|
om_interrupt(cpu *processor,
|
om_interrupt(cpu *processor,
|
unsigned_word cia,
|
unsigned_word cia,
|
unsigned_word ea,
|
unsigned_word ea,
|
om_access_types access,
|
om_access_types access,
|
storage_interrupt_reasons reason)
|
storage_interrupt_reasons reason)
|
{
|
{
|
switch (access) {
|
switch (access) {
|
case om_data_read:
|
case om_data_read:
|
data_storage_interrupt(processor, cia, ea, reason, 0/*!is_store*/);
|
data_storage_interrupt(processor, cia, ea, reason, 0/*!is_store*/);
|
break;
|
break;
|
case om_data_write:
|
case om_data_write:
|
data_storage_interrupt(processor, cia, ea, reason, 1/*is_store*/);
|
data_storage_interrupt(processor, cia, ea, reason, 1/*is_store*/);
|
break;
|
break;
|
case om_instruction_read:
|
case om_instruction_read:
|
instruction_storage_interrupt(processor, cia, reason);
|
instruction_storage_interrupt(processor, cia, reason);
|
break;
|
break;
|
default:
|
default:
|
error("internal error - om_interrupt - unexpected access type %d", access);
|
error("internal error - om_interrupt - unexpected access type %d", access);
|
}
|
}
|
}
|
}
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
om_translate_effective_to_real(om_map *map,
|
om_translate_effective_to_real(om_map *map,
|
unsigned_word ea,
|
unsigned_word ea,
|
om_access_types access,
|
om_access_types access,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia,
|
unsigned_word cia,
|
int abort)
|
int abort)
|
{
|
{
|
om_bat *bat = NULL;
|
om_bat *bat = NULL;
|
om_segment_tlb_entry *segment_tlb_entry = NULL;
|
om_segment_tlb_entry *segment_tlb_entry = NULL;
|
om_page_tlb_entry *page_tlb_entry = NULL;
|
om_page_tlb_entry *page_tlb_entry = NULL;
|
unsigned_word ra;
|
unsigned_word ra;
|
|
|
if (!map->is_relocate) {
|
if (!map->is_relocate) {
|
ra = ea;
|
ra = ea;
|
TRACE(trace_vm, ("ea=0x%lx - direct map - ra=0x%lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - direct map - ra=0x%lx\n",
|
(long)ea, (long)ra));
|
(long)ea, (long)ra));
|
return ra;
|
return ra;
|
}
|
}
|
|
|
/* match with BAT? */
|
/* match with BAT? */
|
bat = om_effective_to_bat(map, ea);
|
bat = om_effective_to_bat(map, ea);
|
if (bat != NULL) {
|
if (bat != NULL) {
|
if (!om_valid_access[1][bat->protection_bits][access]) {
|
if (!om_valid_access[1][bat->protection_bits][access]) {
|
TRACE(trace_vm, ("ea=0x%lx - bat access violation\n", (long)ea));
|
TRACE(trace_vm, ("ea=0x%lx - bat access violation\n", (long)ea));
|
if (abort)
|
if (abort)
|
om_interrupt(processor, cia, ea, access,
|
om_interrupt(processor, cia, ea, access,
|
protection_violation_storage_interrupt);
|
protection_violation_storage_interrupt);
|
else
|
else
|
return MASK(0, 63);
|
return MASK(0, 63);
|
}
|
}
|
|
|
ra = ((ea & bat->block_length_mask) | bat->block_real_page_number);
|
ra = ((ea & bat->block_length_mask) | bat->block_real_page_number);
|
TRACE(trace_vm, ("ea=0x%lx - bat translation - ra=0x%lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - bat translation - ra=0x%lx\n",
|
(long)ea, (long)ra));
|
(long)ea, (long)ra));
|
return ra;
|
return ra;
|
}
|
}
|
|
|
/* translate ea to va using segment map */
|
/* translate ea to va using segment map */
|
segment_tlb_entry = om_effective_to_virtual(map, ea, processor, cia);
|
segment_tlb_entry = om_effective_to_virtual(map, ea, processor, cia);
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
if (segment_tlb_entry == NULL) {
|
if (segment_tlb_entry == NULL) {
|
TRACE(trace_vm, ("ea=0x%lx - segment tlb miss\n", (long)ea));
|
TRACE(trace_vm, ("ea=0x%lx - segment tlb miss\n", (long)ea));
|
if (abort)
|
if (abort)
|
om_interrupt(processor, cia, ea, access,
|
om_interrupt(processor, cia, ea, access,
|
segment_table_miss_storage_interrupt);
|
segment_table_miss_storage_interrupt);
|
else
|
else
|
return MASK(0, 63);
|
return MASK(0, 63);
|
}
|
}
|
#endif
|
#endif
|
/* check for invalid segment access type */
|
/* check for invalid segment access type */
|
if (segment_tlb_entry->invalid_access == access) {
|
if (segment_tlb_entry->invalid_access == access) {
|
TRACE(trace_vm, ("ea=0x%lx - segment access invalid\n", (long)ea));
|
TRACE(trace_vm, ("ea=0x%lx - segment access invalid\n", (long)ea));
|
if (abort)
|
if (abort)
|
om_interrupt(processor, cia, ea, access,
|
om_interrupt(processor, cia, ea, access,
|
protection_violation_storage_interrupt);
|
protection_violation_storage_interrupt);
|
else
|
else
|
return MASK(0, 63);
|
return MASK(0, 63);
|
}
|
}
|
|
|
/* lookup in PTE */
|
/* lookup in PTE */
|
page_tlb_entry = om_virtual_to_real(map, ea, segment_tlb_entry,
|
page_tlb_entry = om_virtual_to_real(map, ea, segment_tlb_entry,
|
access,
|
access,
|
processor, cia);
|
processor, cia);
|
if (page_tlb_entry == NULL) {
|
if (page_tlb_entry == NULL) {
|
TRACE(trace_vm, ("ea=0x%lx - page tlb miss\n", (long)ea));
|
TRACE(trace_vm, ("ea=0x%lx - page tlb miss\n", (long)ea));
|
if (abort)
|
if (abort)
|
om_interrupt(processor, cia, ea, access,
|
om_interrupt(processor, cia, ea, access,
|
hash_table_miss_storage_interrupt);
|
hash_table_miss_storage_interrupt);
|
else
|
else
|
return MASK(0, 63);
|
return MASK(0, 63);
|
}
|
}
|
if (!(om_valid_access
|
if (!(om_valid_access
|
[segment_tlb_entry->key[map->is_problem_state]]
|
[segment_tlb_entry->key[map->is_problem_state]]
|
[page_tlb_entry->protection]
|
[page_tlb_entry->protection]
|
[access])) {
|
[access])) {
|
TRACE(trace_vm, ("ea=0x%lx - page tlb access violation\n", (long)ea));
|
TRACE(trace_vm, ("ea=0x%lx - page tlb access violation\n", (long)ea));
|
if (abort)
|
if (abort)
|
om_interrupt(processor, cia, ea, access,
|
om_interrupt(processor, cia, ea, access,
|
protection_violation_storage_interrupt);
|
protection_violation_storage_interrupt);
|
else
|
else
|
return MASK(0, 63);
|
return MASK(0, 63);
|
}
|
}
|
|
|
/* update change bit as needed */
|
/* update change bit as needed */
|
if (access == om_data_write &&!page_tlb_entry->changed) {
|
if (access == om_data_write &&!page_tlb_entry->changed) {
|
unsigned_word pte_1 = om_read_word(map,
|
unsigned_word pte_1 = om_read_word(map,
|
page_tlb_entry->real_address_of_pte_1,
|
page_tlb_entry->real_address_of_pte_1,
|
processor, cia);
|
processor, cia);
|
om_write_word(map,
|
om_write_word(map,
|
page_tlb_entry->real_address_of_pte_1,
|
page_tlb_entry->real_address_of_pte_1,
|
pte_1 | BIT(56),
|
pte_1 | BIT(56),
|
processor, cia);
|
processor, cia);
|
TRACE(trace_vm, ("ea=0x%lx - set change bit - tlb=0x%lx &pte1=0x%lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - set change bit - tlb=0x%lx &pte1=0x%lx\n",
|
(long)ea, (long)page_tlb_entry,
|
(long)ea, (long)page_tlb_entry,
|
(long)page_tlb_entry->real_address_of_pte_1));
|
(long)page_tlb_entry->real_address_of_pte_1));
|
}
|
}
|
|
|
ra = (page_tlb_entry->masked_real_page_number | om_ea_masked_byte(ea));
|
ra = (page_tlb_entry->masked_real_page_number | om_ea_masked_byte(ea));
|
TRACE(trace_vm, ("ea=0x%lx - page translation - ra=0x%lx\n",
|
TRACE(trace_vm, ("ea=0x%lx - page translation - ra=0x%lx\n",
|
(long)ea, (long)ra));
|
(long)ea, (long)ra));
|
return ra;
|
return ra;
|
}
|
}
|
|
|
|
|
/*
|
/*
|
* Definition of operations for memory management
|
* Definition of operations for memory management
|
*/
|
*/
|
|
|
|
|
/* rebuild all the relevant bat information */
|
/* rebuild all the relevant bat information */
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(void)
|
(void)
|
om_unpack_bat(om_bat *bat,
|
om_unpack_bat(om_bat *bat,
|
spreg ubat,
|
spreg ubat,
|
spreg lbat)
|
spreg lbat)
|
{
|
{
|
/* for extracting out the offset within a page */
|
/* for extracting out the offset within a page */
|
bat->block_length_mask = ((MASKED(ubat, 51, 61) << (17-2))
|
bat->block_length_mask = ((MASKED(ubat, 51, 61) << (17-2))
|
| MASK(63-17+1, 63));
|
| MASK(63-17+1, 63));
|
|
|
/* for checking the effective page index */
|
/* for checking the effective page index */
|
bat->block_effective_page_index = MASKED(ubat, 0, 46);
|
bat->block_effective_page_index = MASKED(ubat, 0, 46);
|
bat->block_effective_page_index_mask = ~bat->block_length_mask;
|
bat->block_effective_page_index_mask = ~bat->block_length_mask;
|
|
|
/* protection information */
|
/* protection information */
|
bat->protection_bits = EXTRACTED(lbat, 62, 63);
|
bat->protection_bits = EXTRACTED(lbat, 62, 63);
|
bat->block_real_page_number = MASKED(lbat, 0, 46);
|
bat->block_real_page_number = MASKED(lbat, 0, 46);
|
}
|
}
|
|
|
|
|
/* rebuild the given bat table */
|
/* rebuild the given bat table */
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(void)
|
(void)
|
om_unpack_bats(om_bats *bats,
|
om_unpack_bats(om_bats *bats,
|
spreg *raw_bats,
|
spreg *raw_bats,
|
msreg msr)
|
msreg msr)
|
{
|
{
|
int i;
|
int i;
|
bats->nr_valid_bat_registers = 0;
|
bats->nr_valid_bat_registers = 0;
|
for (i = 0; i < nr_om_bat_registers*2; i += 2) {
|
for (i = 0; i < nr_om_bat_registers*2; i += 2) {
|
spreg ubat = raw_bats[i];
|
spreg ubat = raw_bats[i];
|
spreg lbat = raw_bats[i+1];
|
spreg lbat = raw_bats[i+1];
|
if ((msr & msr_problem_state)
|
if ((msr & msr_problem_state)
|
? EXTRACTED(ubat, 63, 63)
|
? EXTRACTED(ubat, 63, 63)
|
: EXTRACTED(ubat, 62, 62)) {
|
: EXTRACTED(ubat, 62, 62)) {
|
om_unpack_bat(&bats->bat[bats->nr_valid_bat_registers],
|
om_unpack_bat(&bats->bat[bats->nr_valid_bat_registers],
|
ubat, lbat);
|
ubat, lbat);
|
bats->nr_valid_bat_registers += 1;
|
bats->nr_valid_bat_registers += 1;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
|
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(void)
|
(void)
|
om_unpack_sr(vm *virtual,
|
om_unpack_sr(vm *virtual,
|
sreg *srs,
|
sreg *srs,
|
int which_sr,
|
int which_sr,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
om_segment_tlb_entry *segment_tlb_entry = 0;
|
om_segment_tlb_entry *segment_tlb_entry = 0;
|
sreg new_sr_value = 0;
|
sreg new_sr_value = 0;
|
|
|
/* check register in range */
|
/* check register in range */
|
ASSERT(which_sr >= 0 && which_sr < nr_om_segment_tlb_entries);
|
ASSERT(which_sr >= 0 && which_sr < nr_om_segment_tlb_entries);
|
|
|
/* get the working values */
|
/* get the working values */
|
segment_tlb_entry = &virtual->segment_tlb.entry[which_sr];
|
segment_tlb_entry = &virtual->segment_tlb.entry[which_sr];
|
new_sr_value = srs[which_sr];
|
new_sr_value = srs[which_sr];
|
|
|
/* do we support this */
|
/* do we support this */
|
if (MASKED32(new_sr_value, 0, 0))
|
if (MASKED32(new_sr_value, 0, 0))
|
cpu_error(processor, cia, "unsupported value of T in segment register %d",
|
cpu_error(processor, cia, "unsupported value of T in segment register %d",
|
which_sr);
|
which_sr);
|
|
|
/* update info */
|
/* update info */
|
segment_tlb_entry->key[om_supervisor_state] = EXTRACTED32(new_sr_value, 1, 1);
|
segment_tlb_entry->key[om_supervisor_state] = EXTRACTED32(new_sr_value, 1, 1);
|
segment_tlb_entry->key[om_problem_state] = EXTRACTED32(new_sr_value, 2, 2);
|
segment_tlb_entry->key[om_problem_state] = EXTRACTED32(new_sr_value, 2, 2);
|
segment_tlb_entry->invalid_access = (MASKED32(new_sr_value, 3, 3)
|
segment_tlb_entry->invalid_access = (MASKED32(new_sr_value, 3, 3)
|
? om_instruction_read
|
? om_instruction_read
|
: om_access_any);
|
: om_access_any);
|
segment_tlb_entry->masked_virtual_segment_id =
|
segment_tlb_entry->masked_virtual_segment_id =
|
INSERTED32(EXTRACTED32(new_sr_value, 8, 31),
|
INSERTED32(EXTRACTED32(new_sr_value, 8, 31),
|
31-6-24+1, 31-6); /* aligned ready for pte group addr */
|
31-6-24+1, 31-6); /* aligned ready for pte group addr */
|
}
|
}
|
#endif
|
#endif
|
|
|
|
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(void)
|
(void)
|
om_unpack_srs(vm *virtual,
|
om_unpack_srs(vm *virtual,
|
sreg *srs,
|
sreg *srs,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
int which_sr;
|
int which_sr;
|
for (which_sr = 0; which_sr < nr_om_segment_tlb_entries; which_sr++) {
|
for (which_sr = 0; which_sr < nr_om_segment_tlb_entries; which_sr++) {
|
om_unpack_sr(virtual, srs, which_sr,
|
om_unpack_sr(virtual, srs, which_sr,
|
processor, cia);
|
processor, cia);
|
}
|
}
|
}
|
}
|
#endif
|
#endif
|
|
|
|
|
/* Rebuild all the data structures for the new context as specifed by
|
/* Rebuild all the data structures for the new context as specifed by
|
the passed registers */
|
the passed registers */
|
INLINE_VM\
|
INLINE_VM\
|
(void)
|
(void)
|
vm_synchronize_context(vm *virtual,
|
vm_synchronize_context(vm *virtual,
|
spreg *sprs,
|
spreg *sprs,
|
sreg *srs,
|
sreg *srs,
|
msreg msr,
|
msreg msr,
|
/**/
|
/**/
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
|
|
/* enable/disable translation */
|
/* enable/disable translation */
|
int problem_state = (msr & msr_problem_state) != 0;
|
int problem_state = (msr & msr_problem_state) != 0;
|
int data_relocate = (msr & msr_data_relocate) != 0;
|
int data_relocate = (msr & msr_data_relocate) != 0;
|
int instruction_relocate = (msr & msr_instruction_relocate) != 0;
|
int instruction_relocate = (msr & msr_instruction_relocate) != 0;
|
int little_endian = (msr & msr_little_endian_mode) != 0;
|
int little_endian = (msr & msr_little_endian_mode) != 0;
|
|
|
unsigned_word page_table_hash_mask;
|
unsigned_word page_table_hash_mask;
|
unsigned_word real_address_of_page_table;
|
unsigned_word real_address_of_page_table;
|
|
|
/* update current processor mode */
|
/* update current processor mode */
|
virtual->instruction_map.translation.is_relocate = instruction_relocate;
|
virtual->instruction_map.translation.is_relocate = instruction_relocate;
|
virtual->instruction_map.translation.is_problem_state = problem_state;
|
virtual->instruction_map.translation.is_problem_state = problem_state;
|
virtual->data_map.translation.is_relocate = data_relocate;
|
virtual->data_map.translation.is_relocate = data_relocate;
|
virtual->data_map.translation.is_problem_state = problem_state;
|
virtual->data_map.translation.is_problem_state = problem_state;
|
|
|
/* update bat registers for the new context */
|
/* update bat registers for the new context */
|
om_unpack_bats(&virtual->ibats, &sprs[spr_ibat0u], msr);
|
om_unpack_bats(&virtual->ibats, &sprs[spr_ibat0u], msr);
|
om_unpack_bats(&virtual->dbats, &sprs[spr_dbat0u], msr);
|
om_unpack_bats(&virtual->dbats, &sprs[spr_dbat0u], msr);
|
|
|
/* unpack SDR1 - the storage description register 1 */
|
/* unpack SDR1 - the storage description register 1 */
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
#if (WITH_TARGET_WORD_BITSIZE == 64)
|
real_address_of_page_table = MASKED64(sprs[spr_sdr1], 0, 45);
|
real_address_of_page_table = MASKED64(sprs[spr_sdr1], 0, 45);
|
page_table_hash_mask = MASK64(18+28-EXTRACTED64(sprs[spr_sdr1], 59, 63),
|
page_table_hash_mask = MASK64(18+28-EXTRACTED64(sprs[spr_sdr1], 59, 63),
|
63-7);
|
63-7);
|
#endif
|
#endif
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
real_address_of_page_table = MASKED32(sprs[spr_sdr1], 0, 15);
|
real_address_of_page_table = MASKED32(sprs[spr_sdr1], 0, 15);
|
page_table_hash_mask = (INSERTED32(EXTRACTED32(sprs[spr_sdr1], 23, 31),
|
page_table_hash_mask = (INSERTED32(EXTRACTED32(sprs[spr_sdr1], 23, 31),
|
7, 7+9-1)
|
7, 7+9-1)
|
| MASK32(7+9, 31-6));
|
| MASK32(7+9, 31-6));
|
#endif
|
#endif
|
virtual->instruction_map.translation.real_address_of_page_table = real_address_of_page_table;
|
virtual->instruction_map.translation.real_address_of_page_table = real_address_of_page_table;
|
virtual->instruction_map.translation.page_table_hash_mask = page_table_hash_mask;
|
virtual->instruction_map.translation.page_table_hash_mask = page_table_hash_mask;
|
virtual->data_map.translation.real_address_of_page_table = real_address_of_page_table;
|
virtual->data_map.translation.real_address_of_page_table = real_address_of_page_table;
|
virtual->data_map.translation.page_table_hash_mask = page_table_hash_mask;
|
virtual->data_map.translation.page_table_hash_mask = page_table_hash_mask;
|
|
|
|
|
/* unpack the segment tlb registers */
|
/* unpack the segment tlb registers */
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
#if (WITH_TARGET_WORD_BITSIZE == 32)
|
om_unpack_srs(virtual, srs,
|
om_unpack_srs(virtual, srs,
|
processor, cia);
|
processor, cia);
|
#endif
|
#endif
|
|
|
/* set up the XOR registers if the current endian mode conflicts
|
/* set up the XOR registers if the current endian mode conflicts
|
with what is in the MSR */
|
with what is in the MSR */
|
if (WITH_XOR_ENDIAN) {
|
if (WITH_XOR_ENDIAN) {
|
int i = 1;
|
int i = 1;
|
unsigned mask;
|
unsigned mask;
|
if ((little_endian && CURRENT_TARGET_BYTE_ORDER == LITTLE_ENDIAN)
|
if ((little_endian && CURRENT_TARGET_BYTE_ORDER == LITTLE_ENDIAN)
|
|| (!little_endian && CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN))
|
|| (!little_endian && CURRENT_TARGET_BYTE_ORDER == BIG_ENDIAN))
|
mask = 0;
|
mask = 0;
|
else
|
else
|
mask = WITH_XOR_ENDIAN - 1;
|
mask = WITH_XOR_ENDIAN - 1;
|
while (i - 1 < WITH_XOR_ENDIAN) {
|
while (i - 1 < WITH_XOR_ENDIAN) {
|
virtual->instruction_map.translation.xor[i-1] = mask;
|
virtual->instruction_map.translation.xor[i-1] = mask;
|
virtual->data_map.translation.xor[i-1] = mask;
|
virtual->data_map.translation.xor[i-1] = mask;
|
mask = (mask << 1) & (WITH_XOR_ENDIAN - 1);
|
mask = (mask << 1) & (WITH_XOR_ENDIAN - 1);
|
i = i * 2;
|
i = i * 2;
|
}
|
}
|
}
|
}
|
else {
|
else {
|
/* don't allow the processor to change endian modes */
|
/* don't allow the processor to change endian modes */
|
if ((little_endian && CURRENT_TARGET_BYTE_ORDER != LITTLE_ENDIAN)
|
if ((little_endian && CURRENT_TARGET_BYTE_ORDER != LITTLE_ENDIAN)
|
|| (!little_endian && CURRENT_TARGET_BYTE_ORDER != BIG_ENDIAN))
|
|| (!little_endian && CURRENT_TARGET_BYTE_ORDER != BIG_ENDIAN))
|
cpu_error(processor, cia, "attempt to change hardwired byte order");
|
cpu_error(processor, cia, "attempt to change hardwired byte order");
|
}
|
}
|
}
|
}
|
|
|
/* update vm data structures due to a TLB operation */
|
/* update vm data structures due to a TLB operation */
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(void)
|
(void)
|
vm_page_tlb_invalidate_entry(vm *memory,
|
vm_page_tlb_invalidate_entry(vm *memory,
|
unsigned_word ea)
|
unsigned_word ea)
|
{
|
{
|
int i = om_page_tlb_index(ea);
|
int i = om_page_tlb_index(ea);
|
memory->instruction_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
memory->instruction_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
memory->data_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
memory->data_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
TRACE(trace_vm, ("ea=0x%lx - tlb invalidate entry\n", (long)ea));
|
TRACE(trace_vm, ("ea=0x%lx - tlb invalidate entry\n", (long)ea));
|
}
|
}
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(void)
|
(void)
|
vm_page_tlb_invalidate_all(vm *memory)
|
vm_page_tlb_invalidate_all(vm *memory)
|
{
|
{
|
int i;
|
int i;
|
for (i = 0; i < nr_om_page_tlb_entries; i++) {
|
for (i = 0; i < nr_om_page_tlb_entries; i++) {
|
memory->instruction_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
memory->instruction_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
memory->data_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
memory->data_tlb.entry[i].masked_virtual_segment_id = MASK(0, 63);
|
}
|
}
|
TRACE(trace_vm, ("tlb invalidate all\n"));
|
TRACE(trace_vm, ("tlb invalidate all\n"));
|
}
|
}
|
|
|
|
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(vm_data_map *)
|
(vm_data_map *)
|
vm_create_data_map(vm *memory)
|
vm_create_data_map(vm *memory)
|
{
|
{
|
return &memory->data_map;
|
return &memory->data_map;
|
}
|
}
|
|
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(vm_instruction_map *)
|
(vm_instruction_map *)
|
vm_create_instruction_map(vm *memory)
|
vm_create_instruction_map(vm *memory)
|
{
|
{
|
return &memory->instruction_map;
|
return &memory->instruction_map;
|
}
|
}
|
|
|
|
|
STATIC_INLINE_VM\
|
STATIC_INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
vm_translate(om_map *map,
|
vm_translate(om_map *map,
|
unsigned_word ea,
|
unsigned_word ea,
|
om_access_types access,
|
om_access_types access,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia,
|
unsigned_word cia,
|
int abort)
|
int abort)
|
{
|
{
|
switch (CURRENT_ENVIRONMENT) {
|
switch (CURRENT_ENVIRONMENT) {
|
case USER_ENVIRONMENT:
|
case USER_ENVIRONMENT:
|
case VIRTUAL_ENVIRONMENT:
|
case VIRTUAL_ENVIRONMENT:
|
return ea;
|
return ea;
|
case OPERATING_ENVIRONMENT:
|
case OPERATING_ENVIRONMENT:
|
return om_translate_effective_to_real(map, ea, access,
|
return om_translate_effective_to_real(map, ea, access,
|
processor, cia,
|
processor, cia,
|
abort);
|
abort);
|
default:
|
default:
|
error("internal error - vm_translate - bad switch");
|
error("internal error - vm_translate - bad switch");
|
return 0;
|
return 0;
|
}
|
}
|
}
|
}
|
|
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
vm_real_data_addr(vm_data_map *map,
|
vm_real_data_addr(vm_data_map *map,
|
unsigned_word ea,
|
unsigned_word ea,
|
int is_read,
|
int is_read,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
return vm_translate(&map->translation,
|
return vm_translate(&map->translation,
|
ea,
|
ea,
|
is_read ? om_data_read : om_data_write,
|
is_read ? om_data_read : om_data_write,
|
processor,
|
processor,
|
cia,
|
cia,
|
1); /*abort*/
|
1); /*abort*/
|
}
|
}
|
|
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(unsigned_word)
|
(unsigned_word)
|
vm_real_instruction_addr(vm_instruction_map *map,
|
vm_real_instruction_addr(vm_instruction_map *map,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
return vm_translate(&map->translation,
|
return vm_translate(&map->translation,
|
cia,
|
cia,
|
om_instruction_read,
|
om_instruction_read,
|
processor,
|
processor,
|
cia,
|
cia,
|
1); /*abort*/
|
1); /*abort*/
|
}
|
}
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(instruction_word)
|
(instruction_word)
|
vm_instruction_map_read(vm_instruction_map *map,
|
vm_instruction_map_read(vm_instruction_map *map,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
unsigned_word ra = vm_real_instruction_addr(map, processor, cia);
|
unsigned_word ra = vm_real_instruction_addr(map, processor, cia);
|
ASSERT((cia & 0x3) == 0); /* always aligned */
|
ASSERT((cia & 0x3) == 0); /* always aligned */
|
if (WITH_XOR_ENDIAN)
|
if (WITH_XOR_ENDIAN)
|
ra ^= map->translation.xor[sizeof(instruction_word) - 1];
|
ra ^= map->translation.xor[sizeof(instruction_word) - 1];
|
return core_map_read_4(map->code, ra, processor, cia);
|
return core_map_read_4(map->code, ra, processor, cia);
|
}
|
}
|
|
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(int)
|
(int)
|
vm_data_map_read_buffer(vm_data_map *map,
|
vm_data_map_read_buffer(vm_data_map *map,
|
void *target,
|
void *target,
|
unsigned_word addr,
|
unsigned_word addr,
|
unsigned nr_bytes,
|
unsigned nr_bytes,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
unsigned count;
|
unsigned count;
|
for (count = 0; count < nr_bytes; count++) {
|
for (count = 0; count < nr_bytes; count++) {
|
unsigned_1 byte;
|
unsigned_1 byte;
|
unsigned_word ea = addr + count;
|
unsigned_word ea = addr + count;
|
unsigned_word ra = vm_translate(&map->translation,
|
unsigned_word ra = vm_translate(&map->translation,
|
ea, om_data_read,
|
ea, om_data_read,
|
processor, /*processor*/
|
processor, /*processor*/
|
cia, /*cia*/
|
cia, /*cia*/
|
processor != NULL); /*abort?*/
|
processor != NULL); /*abort?*/
|
if (ra == MASK(0, 63))
|
if (ra == MASK(0, 63))
|
break;
|
break;
|
if (WITH_XOR_ENDIAN)
|
if (WITH_XOR_ENDIAN)
|
ra ^= map->translation.xor[0];
|
ra ^= map->translation.xor[0];
|
if (core_map_read_buffer(map->read, &byte, ra, sizeof(byte))
|
if (core_map_read_buffer(map->read, &byte, ra, sizeof(byte))
|
!= sizeof(byte))
|
!= sizeof(byte))
|
break;
|
break;
|
((unsigned_1*)target)[count] = T2H_1(byte);
|
((unsigned_1*)target)[count] = T2H_1(byte);
|
}
|
}
|
return count;
|
return count;
|
}
|
}
|
|
|
|
|
INLINE_VM\
|
INLINE_VM\
|
(int)
|
(int)
|
vm_data_map_write_buffer(vm_data_map *map,
|
vm_data_map_write_buffer(vm_data_map *map,
|
const void *source,
|
const void *source,
|
unsigned_word addr,
|
unsigned_word addr,
|
unsigned nr_bytes,
|
unsigned nr_bytes,
|
int violate_read_only_section,
|
int violate_read_only_section,
|
cpu *processor,
|
cpu *processor,
|
unsigned_word cia)
|
unsigned_word cia)
|
{
|
{
|
unsigned count;
|
unsigned count;
|
unsigned_1 byte;
|
unsigned_1 byte;
|
for (count = 0; count < nr_bytes; count++) {
|
for (count = 0; count < nr_bytes; count++) {
|
unsigned_word ea = addr + count;
|
unsigned_word ea = addr + count;
|
unsigned_word ra = vm_translate(&map->translation,
|
unsigned_word ra = vm_translate(&map->translation,
|
ea, om_data_write,
|
ea, om_data_write,
|
processor,
|
processor,
|
cia,
|
cia,
|
processor != NULL); /*abort?*/
|
processor != NULL); /*abort?*/
|
if (ra == MASK(0, 63))
|
if (ra == MASK(0, 63))
|
break;
|
break;
|
if (WITH_XOR_ENDIAN)
|
if (WITH_XOR_ENDIAN)
|
ra ^= map->translation.xor[0];
|
ra ^= map->translation.xor[0];
|
byte = T2H_1(((unsigned_1*)source)[count]);
|
byte = T2H_1(((unsigned_1*)source)[count]);
|
if (core_map_write_buffer((violate_read_only_section
|
if (core_map_write_buffer((violate_read_only_section
|
? map->read
|
? map->read
|
: map->write),
|
: map->write),
|
&byte, ra, sizeof(byte)) != sizeof(byte))
|
&byte, ra, sizeof(byte)) != sizeof(byte))
|
break;
|
break;
|
}
|
}
|
return count;
|
return count;
|
}
|
}
|
|
|
|
|
/* define the read/write 1/2/4/8/word functions */
|
/* define the read/write 1/2/4/8/word functions */
|
|
|
#define N 1
|
#define N 1
|
#include "vm_n.h"
|
#include "vm_n.h"
|
#undef N
|
#undef N
|
|
|
#define N 2
|
#define N 2
|
#include "vm_n.h"
|
#include "vm_n.h"
|
#undef N
|
#undef N
|
|
|
#define N 4
|
#define N 4
|
#include "vm_n.h"
|
#include "vm_n.h"
|
#undef N
|
#undef N
|
|
|
#define N 8
|
#define N 8
|
#include "vm_n.h"
|
#include "vm_n.h"
|
#undef N
|
#undef N
|
|
|
#define N word
|
#define N word
|
#include "vm_n.h"
|
#include "vm_n.h"
|
#undef N
|
#undef N
|
|
|
|
|
|
|
#endif /* _VM_C_ */
|
#endif /* _VM_C_ */
|
|
|