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