Changeset 758 for trunk/softs/tsar_boot/src/reset_utils.c
- Timestamp:
- Jul 24, 2014, 3:19:18 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/softs/tsar_boot/src/reset_utils.c
r703 r758 8 8 9 9 #include <reset_utils.h> 10 11 /* 12 * pread(size_t file_offset, void* buf, size_t nbyte, size_t offset) 13 * 14 * read from disk into buffer "nbyte" bytes from (file_offset + offset) 15 * 10 #include <reset_tty.h> 11 #include <reset_ioc.h> 12 #include <io.h> 13 14 /** 16 15 * \param file_offset: Disk relative offset of file 17 16 * \param buf: Destination buffer 18 17 * \param nbyte: Number of bytes to read 19 18 * \param offset: File relative offset 19 * 20 * \brief read from disk into buffer "nbyte" bytes from (file_offset + offset) 20 21 * 21 22 * \note Absolute disk offset (in bytes) is (file_offset + offset) … … 57 58 if (offset_blk != blk_buf_idx) { 58 59 if (reset_ioc_read(offset_blk, (void*)&blk_buf, 1)) { 59 return -1; 60 return -1; 60 61 } 61 62 } 62 63 blk_buf_idx = offset_blk; 63 read_nbyte = (nbyte > unaligned_nbyte) ? unaligned_nbyte : nbyte; 64 read_nbyte = (nbyte > unaligned_nbyte) ? unaligned_nbyte : nbyte; 64 65 memcpy((void*)dst, (void*)&blk_buf.b[offset], read_nbyte); 65 66 nbyte -= read_nbyte; … … 70 71 * Read aligned bytes directly to buffer 71 72 */ 72 size_t nblk = nbyte / BLOCK_SIZE; 73 size_t nblk = nbyte / BLOCK_SIZE; 73 74 if (nblk) { 74 75 if (reset_ioc_read(offset_blk, (void*)&dst[read_nbyte], nblk)) { … … 91 92 read_nbyte += nbyte; 92 93 } 93 return read_nbyte; 94 } 95 96 /******************************************************************** 97 * proctime() 98 * 99 * Returns processor local time. 100 ********************************************************************/ 101 inline unsigned int proctime() 102 { 103 unsigned int ret; 104 asm volatile ("mfc0 %0, $9":"=r" (ret)); 105 return ret; 106 } 107 108 /******************************************************************** 109 * memcpy( _dst, _src, size ) 110 * 111 * Transfer data between two memory buffers. 112 * 113 * \param _dst : Destination buffer base address 94 return read_nbyte; 95 } 96 97 /** 98 * \param _dst : Destination buffer base address 114 99 * \param _src : Source buffer base address 115 * \param size : Number of bytes to transfer 116 * 117 ********************************************************************/ 100 * \param size : Number of bytes to transfer 101 * 102 * \brief Transfer data between two memory buffers. 103 */ 118 104 void* memcpy(void *_dst, const void *_src, size_t n) 119 105 { … … 135 121 } 136 122 137 /******************************************************************** 138 * memset( _dst, value, size ) 139 * 140 * Initialize memory buffers with predefined value. 141 * 142 * \param _dst : Destination buffer base address 143 * \param value : Initialization value 123 /** 124 * \param _dst : Destination buffer base address 125 * \param value : Initialization value 144 126 * \param size : Number of bytes to initialize 145 127 * 146 ********************************************************************/ 128 * \brief Initialize memory buffers with predefined value. 129 */ 147 130 void* memset(void *_dst, int c, size_t len) 148 131 { … … 179 162 } 180 163 181 /******************************************************************** 182 * check_elf_header(Elf32_Ehdr*) 183 * 184 * Verify that ELF file is valid and that the number of program 185 * headers does not exceed the defined maximum 186 * 164 /** 187 165 * \param ehdr : ELF header pointer 188 166 * 189 ********************************************************************/ 167 * \brief Verify that ELF file is valid and that the number of program headers 168 * does not exceed the defined maximum 169 */ 190 170 void check_elf_header(Elf32_Ehdr *ehdr) 191 171 { … … 205 185 * Verification of Program Headers table size. It must be 206 186 * smaller than the work size allocated for the 207 * elf_pht[ PHDR_ARRAY_SIZE] array208 */ 209 if (ehdr->e_phnum > PHDR_ARRAY_SIZE)187 * elf_pht[RESET_PHDR_ARRAY_SIZE] array 188 */ 189 if (ehdr->e_phnum > RESET_PHDR_ARRAY_SIZE) 210 190 { 211 191 reset_puts("[RESET ERROR] ELF PHDR table size too large\n"); … … 214 194 } 215 195 216 /******************************************************************** 217 * reset_print_elf_phdr( elf_phdr_ptr ) 218 * 219 * Print some fields of a ELF program header 220 * 196 /** 221 197 * \param elf_phdr_ptr : Pointer to the ELF program header to print 222 198 * 223 ********************************************************************/ 199 * \brief Print some fields of a ELF program header 200 */ 224 201 void reset_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr) 225 202 { … … 243 220 } 244 221 245 246 /******************************************************************** 247 * reset_mcc_inval() 248 * 249 * Invalidate all data cache lines corresponding to a memory buffer 250 * (identified by an address and a size) in L2 cache. 251 ********************************************************************/ 252 #if USE_IOB 253 void reset_mcc_invalidate (const void * buffer, size_t size) 254 { 255 addr_t *mcc_address = (addr_t*)MCC_PADDR_BASE; 256 257 // get the hard lock assuring exclusive access to MEMC 258 while (ioread32(&mcc_address[MCC_LOCK])); 259 260 // write invalidate paremeters on the memory cache this preloader 261 // use only the cluster 0 and then the HI bits are not used 262 263 iowrite32(&mcc_address[MCC_ADDR_LO], (unsigned int) buffer); 264 iowrite32(&mcc_address[MCC_ADDR_HI], (unsigned int) 0); 265 iowrite32(&mcc_address[MCC_LENGTH] , (unsigned int) size); 266 iowrite32(&mcc_address[MCC_CMD] , (unsigned int) MCC_CMD_INVAL); 267 268 // release the lock protecting MEMC 269 iowrite32(&mcc_address[MCC_LOCK], (unsigned int) 0); 270 } 271 #endif 272 273 /******************************************************************** 274 * reset_dcache_buf_invalidate() 275 * 276 * Invalidate all data cache lines corresponding to a memory buffer 277 * (identified by an address and a size) in L1 cache and L2 cache. 278 ********************************************************************/ 279 #if (CACHE_COHERENCE == 0) || USE_IOB 280 void reset_buf_invalidate (const void * buffer, size_t line_size, size_t size) 281 { 282 unsigned int i; 283 284 // iterate on cache lines 285 for (i = 0; i <= size; i += line_size) 286 { 287 asm volatile( 288 " cache %0, %1" 289 :// no outputs 290 :"i" (0x11), "R" (*((unsigned char *) buffer + i)) 291 ); 292 } 293 294 #if USE_IOB 295 reset_mcc_invalidate(buffer, size); 296 #endif 297 } 298 #endif 299 300 // vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab 222 /* 223 * vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab 224 */
Note: See TracChangeset
for help on using the changeset viewer.