src/memory.h

branch
experimental_memory_mapper_v2
changeset 128
3246b74d96bc
parent 112
a392eb8f9806
     1.1 --- a/src/memory.h	Wed Jan 16 00:41:51 2013 +0000
     1.2 +++ b/src/memory.h	Fri Jan 18 17:03:48 2013 +0000
     1.3 @@ -45,14 +45,57 @@
     1.4   * Memory mapping
     1.5   ******************/
     1.6  
     1.7 -typedef enum {
     1.8 -	MEM_ALLOWED = 0,
     1.9 -	MEM_PAGEFAULT,		// Page fault -- page not present
    1.10 -	MEM_PAGE_NO_WE,		// Page not write enabled
    1.11 -	MEM_KERNEL,			// User attempted to access kernel memory
    1.12 -	MEM_UIE				// User Nonmemory Location Access
    1.13 -} MEM_STATUS;
    1.14 +/***
    1.15 + * An entry in MAP RAM looks like this:
    1.16 + *
    1.17 + *    15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0
    1.18 + *   +-----------------------------------------------+
    1.19 + *   |  |  |  |  |  |  |   MA[21..12] ADDRESS BITS   |
    1.20 + *   +-----------------------------------------------+
    1.21 + *
    1.22 + *   Bits 0 thru 9: High 10 address bits (mapping)
    1.23 + *   Bits 10 thru 15: Page bits
    1.24 + *     B10: PS4
    1.25 + *     B11: PS3
    1.26 + *     B12: PS2
    1.27 + *     B13: PS0
    1.28 + *     B14: PS1
    1.29 + *     B15: WE+
    1.30 + *
    1.31 + * Page bit meanings:
    1.32 + *    PS4, 3 and 2 are unused.
    1.33 + *    PS1:PS0:
    1.34 + *      PS1  PS0   Meaning
    1.35 + *      ---  ---   -------
    1.36 + *       0    0    Page not present
    1.37 + *       0    1    Page present but has not been accessed
    1.38 + *       1    0    Page has been accessed but not written
    1.39 + *       1    1    Page has been accessed and written to (is dirty)
    1.40 + *
    1.41 + *    WE+: Write Enable. Set to 1 if the page is writable.
    1.42 + *
    1.43 + * Each RAM page is 4096 bytes.
    1.44 + */
    1.45  
    1.46 +/// Known page bits and their values
    1.47 +enum {
    1.48 +	PAGE_BIT_PS0 = 0x08,	///< PS0 page status bit
    1.49 +	PAGE_BIT_PS1 = 0x10,	///< PS1 (page accessed) page bit
    1.50 +	PAGE_BIT_WE  = 0x20		///< WE (write enable) page bit
    1.51 +};
    1.52 +
    1.53 +/// Get the Map RAM entry for the specified page
    1.54 +#define MAPRAM(page) (((uint16_t)state.map[page*2] << 8) + ((uint16_t)state.map[(page*2)+1]))
    1.55 +/// Get the page number for a given address
    1.56 +#define MAP_ADDR_TO_PAGE(addr) (((addr) >> 12) & 0x3FF)
    1.57 +/// Get the Map RAM entry for the specified virtual address
    1.58 +#define MAPRAM_ADDR(addr) (MAPRAM(MAP_ADDR_TO_PAGE(addr)))
    1.59 +/// Map an address from CPU address space to physical memory
    1.60 +#define MAP_ADDR(addr) (((MAPRAM_ADDR(addr) & 0x3FF) << 12) | (addr & 0xFFF))
    1.61 +/// Get the page bits associated with the mapping for a given physical memory address
    1.62 +#define MAP_PAGEBITS(addr) ((MAPRAM_ADDR(addr) >> 10) & 0x3F)
    1.63 +
    1.64 +#if 0
    1.65  /**
    1.66   * @brief 	Check memory access permissions for a given address.
    1.67   * @param	addr		Address.
    1.68 @@ -63,19 +106,18 @@
    1.69  MEM_STATUS checkMemoryAccess(uint32_t addr, bool writing);
    1.70  
    1.71  /**
    1.72 - * @brief	Map a CPU memory address into physical memory space.
    1.73 - * @param	addr		Address.
    1.74 - * @param	writing		true if writing to memory, false if reading.
    1.75 - * @return	Address, remapped into physical memory.
    1.76 - */
    1.77 -uint32_t mapAddr(uint32_t addr, bool writing);
    1.78 -
    1.79 -/**
    1.80   * @brief   Check access flags for a DMA transfer and trigger an exception if
    1.81   *          the access is not permitted
    1.82   * @param   reading     true if reading from memory, false if writing
    1.83 - * @return  true if the access is permitted, false if not
    1.84   */
    1.85  bool access_check_dma(int reading);
    1.86 +#endif
    1.87 +
    1.88 +
    1.89 +/**
    1.90 + * Check memory access permissions for a DMA operation.
    1.91 + * @return  true if the access is permitted, false if not
    1.92 + */
    1.93 +bool access_check_dma(void);
    1.94  
    1.95  #endif