SkyEye hardware simulation platform, hardware simulation implementation 3

Source: Internet
Author: User
Article title: SkyEye hardware simulation platform, hardware simulation implementation 3. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
   1. MMU and Memory system structure
   Figure 0-1 system structure of MMU and Memory in the arm system
    
The system structure of MMU and Memory in the arm system is 0 1. However, the time difference between the specific CPU implementation and MMU may be relatively large, which may be simplified and extended. the MMU simulation of SkyEye is based on this and provides a standard interface, it is divided into two main parts: MMU simulation sub-modules irrelevant to the specific CPU type and MMU simulation sub-modules related to the specific CPU type.
  
   2. Basic flowchart of arm data access
The basic process of arm CPU data access is as follows: 0 2.
   Figure 0-2 basic process of arm CPU data access
    
   3. Unified MMU interface
  
Data structure
  
Typedef struct mmu_state_t {
Armwordcontrol; // CP15 control register
Armwordtranslation_table_base; // CP15 translation table base register
Armworddomain_access_control; // CP15 domain access control register
Armwordfault_status; // CP15 fault status register
Armwordfault_address; // CP15 fault address register
Armwordlast_domain; // last access domain
Armwordprocess_id; // CP15 process id register
Mmu_ops_tops;
Union {
Sa_mmu_tsa_mmu;
Arm7100_mmu_t arm7100_mmu;
} U;
} Mmu_state_t;
  
Typedef struct mmu_ops_s {
Int (* init) (armul_State * state);/* initilization */
Void (* exit) (armul_State * state);/* free on exit */
Fault_t (* read_byte) (ARMul_State * state, ARMword va, armword * data );
Fault_t (* write_byte) (ARMul_State * state, ARMword va, armword data );
Fault_t (* read_halfword) (ARMul_State * state, ARMword va, armword * data );
Fault_t (* write_halfword) (ARMul_State * state, ARMword va, armword data );
Fault_t (* read_word) (ARMul_State * state, ARMword va, armword * data );
Fault_t (* write_word) (ARMul_State * state, ARMword va, armword data );
Fault_t (* load_instr) (ARMul_State * state, ARMword va, armword * instr );
Void (* mcr) (ARMul_State * state, ARMword instr, armword val );
ARMword (* mrc) (ARMul_State * state, armword instr );
} Mmu_ops_t;
  
Mmu of the mmu_state_t type in the armul_State data structure represents the MMU state in the simulation. Ops in mmu_state_t provides interface functions for specific mmu, and also includes a joint structure u for the data structure implemented by specific mmu.
  
   4. MMU simulation sub-module unrelated to the specific CPU type
The MMU simulation sub-module unrelated to the specific CPU type is the basis for MMU simulation. it simulates MMU elements such as TLB, TTW, access control, CACHE, Write Buffer, and Read Buffer, it also provides a unified interface that can be flexibly combined to implement specific MMU simulation.
  
TLB implementation (mmu/tlb. [ch])
TLB is a table whose table items contain address ing information and access control information. The Address Translation information can be searched in the memory through TTW only when the table cannot be queried.
  
Data structure
  
TLB ing type
Typedef enum tlb_mapping_t {
TLB_INVALID = 0,
TLB_SMALLPAGE = 1,
TLB_LARGEPAGE = 2,
TLB_SECTION = 3
} Tlb_mapping_t;
  
TLB table items
  
Typedef struct tlb_entry_t {
Armwordvirt_addr; // virtual address
Armwordphys_addr; // physical address
Armwordperms; // access permission
Armworddomain; // access domain
Tlb_mapping_tmapping; // tlb mapping type
} Tlb_entry_t;
  
TLB table
  
Typedef struct tlb_s {
Int num;/* num of tlb entry */
Int cycle;/* current tlb cycle, used for allocate tlb_entry */
Tlb_entry_t * entrys;
} Tlb_t;
  
Interface functions
  
Int mmu_tlb_init (tlb_t * tlb_t, int num );
Initialize TLB
Void mmu_tlb_exit (tlb_t * tlb_t );
Release TLB
Void mmu_tlb_invalidate_all (armul_State * state, tlb_t * tlb_t );
All tlb_entries are invalid.
Void mmu_tlb_invalidate_entry (ARMul_State * state, tlb_t * tlb_t, armword 1__addr );
The tlb_entry containing the specified performance_addr is invalid.
Tlb_entry_t * mmu_tlb_search (ARMul_State * state, tlb_t * tlb_t, armword 1__addr );
Search for tlb_entry based on pai_addr
  
Implementation of TTW (mmu/tlb. [ch])
In the arm System, page address conversion is realized through Level 2 ING.
  
Interface functions
  
Fault_t translate (ARMul_State * state, armword implements _addr, tlb_t * tlb_t, tlb_entry_t ** tlb)
{
/* First, search for the TLB table. if not, execute TTW and update the TLB table */
  
* Tlb = mmu_tlb_search (state, tlb_t, virt_addr);/* find tlb */
If (! * Tlb ){
/* Not Found. TTW */
Armword l1addr, l1desc;/* Level 1 descriptor address, Level 1 descriptor */
Tlb_entry_t entry;
  
L1addr = state-> mmu. translation_table_base & 0xFFFFC000;
L1addr = (l1addr | (virt_addr> 18 ))&~ 3;/* calculate the first-level descriptor address */
L1desc = mem_read_word (state, l1addr);/* read level 1 descriptor */
Switch (l1desc & 3 ){
Case 0:
Case 3:
Return SECTION_TRANSLATION_FAULT;
Case 1:
/* Page conversion */
{
Armword l2addr, l2desc;/* second-level descriptor address, second-level descriptor */
  
L2addr = l1desc & 0xFFFFFC00;
/* Calculate the second-level descriptor address */
L2addr = (l2addr | (virt_addr & 0x000FF000)> 10 ))&~ 3;
/* Read the second-level descriptor */
L2desc = mem_read_word (state, l2addr );
  
Entry. pai_addr = pai_addr;
Entry. phys_addr = l2desc;
Entry. perms = l2desc & 0x00000FFC;
Entry. domain = (l1desc> 5) & 0x0000000F;
Switch (l2desc & 3 ){
Case 0:
Case 3:
State-> mmu. last_domain = entry. domain;
Return PAGE_TRANSLATION_FAULT;
Case 1:
Entry. mapping = TLB_LARGEPAGE;/* large page */
Break;
Case 2:
Entry. mapping = TLB_SMALLPAGE;/* Small page */
Break;
}
}
Break;
Case 2:
/* Segment conversion */
Entry. pai_addr = pai_addr;
Entry. phys_addr = l1desc;
Entry. perms = l1desc & 0x00000C0C;
Entry. domain = (l1desc> 5) & 0x0000000F;
Entry. mapping = TLB_SECTION;
Break;
}
Entry. performance_addr & = tlb_masks [entry. mapping];
Entry. phys_addr & = tlb_masks [entry. mapping];
  
/* Update tlb */
* Tlb = & tlb_t-> entrys [tlb_t-> cycle];
Tlb_t-> cycle = (tlb_t-> cycle + 1) % tlb_t-> num;
** Tlb = entry;
}
State-> mmu. last_domain = (* tlb)-> domain;
Return NO_FAULT;
}
  
Implementation of access control (mmu/tlb. [ch])
  
Interface functions
  
Fault_t check_access (ARMul_State * state, armword pai_addr,
Tlb_entry_t * tlb, int read );
  
Implementation of CACHE (mmu/cache. [ch])
  
In arm systems, only associated CACHE is implemented. The associated CACHE of a group is divided into multiple groups. a group contains multiple CACHE lines and a 32-bit address can be represented.
  
Tag Set Word 1 0
  
Data structure
  
Cache row
  
Typedef struct cache_line_t {
Armword tag;/* cache line align address |
Bit2: last half dirty
Bit1: first half dirty
Bit0: cache valid flag
*/
Armword pa;/* physical address */
Armword * data;/* array of cached data */
} Cache_line_t;
  
# Define TAG_VALID_FLAG 0x00000001
# Deprecision TAG_FIRST_HALF_DIRTY 0x00000002
# Define TAG_LAST_HALF_DIRTY0x00000004
  
Cache Group
  
Typedef struct cache_set_s {
Cache_line_t * lines;
Int cycle;/* used for cache line allocation */
} Cache_set_t;
  
Cache structure
  
Typedef struct cache_s {
Intwidth;/* bytes in a line */
Int way;/* way of set asscociate */
Intset;/* num of set */
Int w_mode;/* write back or write through */
// Int a_mode;/* alloc mode: random or round-bin */
Cache_set_t * sets;
} Cache_t;
  
Interface functions
  
/* Cache initialization and release */
Int mmu_cache_init (cache_t * cache_t, int width, int way, int set, int w_mode );
Void mmu_cache_exit (cache_t * cache_t );
/* Cache search and allocation */
Cache_line_t * mmu_cache_search (ARMul_State * state, cache_t * cache_t, armword va );
Cache_line_t * mmu_cache_alloc (ARMul_State * state, cache_t * cache_t, ARMword va, armword pa

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.