source: trunk/softs/tsar_boot/src/reset_utils.c @ 654

Last change on this file since 654 was 653, checked in by cfuguet, 11 years ago

Introducing a RAMDISK driver in the preloader.

When using RAMDISK, execute the make command with the flags
SOCLIB=1 and RAMDISK=1. The RDK_PADDR_BASE variable must
also be set on the conf/<platform>/defs_platform.h

These modifications are backward compatibles. Therefore,
when no using RAMDISK, none modifications applied on the
platform configuration file.

File size: 4.7 KB
RevLine 
[425]1/**
[586]2 * \file    : reset_utils.c
[425]3 * \date    : August 2012
4 * \author  : Cesar Fuguet
5 *
[586]6 * Definition of utilities functions used by the TSAR pre-loader
[425]7 */
8
[586]9#include <reset_utils.h>
[425]10
[653]11/********************************************************************
[586]12 * proctime()
13 *
14 * Returns processor local time.
[653]15 ********************************************************************/
[586]16inline unsigned int proctime() 
17{
18    unsigned int ret;
19    asm volatile ("mfc0   %0,        $9":"=r" (ret));
20    return ret;
21}
22
[653]23/********************************************************************
[425]24 * memcpy( _dst, _src, size )
25 *
[586]26 * Transfer data between two memory buffers.
[425]27 *
28 * \param _dst   : Destination buffer base address
29 * \param _src   : Source buffer base address
30 * \param size   : Number of bytes to transfer
31 *
[653]32 ********************************************************************/
[425]33void * memcpy(void *_dst, const void *_src, unsigned int size)
34{
35    unsigned int *dst = _dst;
36    const unsigned int *src = _src;
37    if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
[586]38        while (size > 3) 
39        {
[425]40            *dst++ = *src++;
41            size -= 4;
42        }
43
44    unsigned char *cdst = (unsigned char*) dst;
45    unsigned char *csrc = (unsigned char*) src;
46
[586]47    while (size--) 
48    {
[425]49        *cdst++ = *csrc++;
50    }
51    return _dst;
52}
53
[653]54/********************************************************************
[425]55 * memset( _dst, value, size )
56 *
57 * Initialize memory buffers with predefined value.
58 *
59 * \param _dst   : Destination buffer base address
60 * \param value  : Initialization value
61 * \param size   : Number of bytes to initialize
62 *
[653]63 ********************************************************************/
[425]64void * memset(void *_dst, const int value, unsigned int size)
65{
66    char * dst = (char *) _dst;
67
68    while(size--) *dst++ = (char) value;
69
70    return _dst;
71}
72
[653]73/********************************************************************
[586]74 * reset_print_elf_phdr( elf_phdr_ptr )
[425]75 *
76 * Print some fields of a ELF program header
77 *
78 * \param elf_phdr_ptr : Pointer to the ELF program header to print
79 *
[653]80 ********************************************************************/
[586]81void reset_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr)
[425]82{
[586]83    reset_puts("- type   : ");
84    reset_putx(elf_phdr_ptr->p_type);
[425]85
[586]86    reset_puts("\n- offset : ");
87    reset_putx(elf_phdr_ptr->p_offset);
[425]88
[586]89    reset_puts("\n- vaddr  : ");
90    reset_putx(elf_phdr_ptr->p_vaddr);
[425]91
[586]92    reset_puts("\n- paddr  : ");
93    reset_putx(elf_phdr_ptr->p_paddr);
[425]94
[586]95    reset_puts("\n- filesz : ");
96    reset_putx(elf_phdr_ptr->p_filesz);
[425]97
[586]98    reset_puts("\n- memsz  : ");
99    reset_putx(elf_phdr_ptr->p_memsz);
[425]100
[586]101    reset_puts("\n- flags  : ");
102    reset_putx(elf_phdr_ptr->p_flags);
[425]103
[586]104    reset_puts("\n- align  : ");
105    reset_putx(elf_phdr_ptr->p_align);
[425]106}
107
[653]108
109/********************************************************************
110 * reset_mcc_inval()
111 *
112 * Invalidate all data cache lines corresponding to a memory buffer
113 * (identified by an address and a size) in L2 cache.
114 ********************************************************************/
115#if USE_IOB
116void reset_mcc_invalidate ( const void * buffer,
117                            unsigned int size)
118{
119    unsigned int * mcc_address = (unsigned int *)MCC_PADDR_BASE;
120
121    // get the hard lock assuring exclusive access to MEMC
122    while (ioread32(&mcc_address[MCC_LOCK]));
123
124    // write invalidate paremeters on the memory cache this preloader
125    // use only the cluster 0 and then the HI bits are not used
126   
127    iowrite32(&mcc_address[MCC_ADDR_LO], (unsigned int) buffer);
128    iowrite32(&mcc_address[MCC_ADDR_HI], (unsigned int) 0);
129    iowrite32(&mcc_address[MCC_LENGTH] , (unsigned int) size);
130    iowrite32(&mcc_address[MCC_CMD]    , (unsigned int) MCC_CMD_INVAL);
131
132    // release the lock protecting MEMC
133    iowrite32(&mcc_address[MCC_LOCK], (unsigned int) 0);
134}
135#endif
136
137/********************************************************************
138 * reset_dcache_buf_invalidate()
139 *
140 * Invalidate all data cache lines corresponding to a memory buffer
141 * (identified by an address and a size) in L1 cache and L2 cache.
142 ********************************************************************/
143#if (CACHE_COHERENCE == 0) || USE_IOB
144void reset_buf_invalidate ( const void * buffer,
145                            unsigned int line_size,
146                            unsigned int size)
147{
148    unsigned int i;
149
150    // iterate on cache lines
151    for (i = 0; i <= size; i += line_size) 
152    {
153        asm volatile(
154            " cache %0, %1"
155            :// no outputs
156            :"i" (0x11), "R" (*((unsigned char *) buffer + i))
157            );
158    }
159
160#if USE_IOB
161    reset_mcc_invalidate(buffer, count * 512);
162#endif
163}
164#endif
165
[425]166// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.