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

Last change on this file since 673 was 655, checked in by cfuguet, 11 years ago

Fixing bug introduced in last commit :

  • When using IO bridge, some header files were missing in the reset_utils.h file
File size: 5.3 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;
[655]37    if ( !((unsigned int)dst & 3) && !((unsigned int)src & 3) )
38    {
[586]39        while (size > 3) 
40        {
[425]41            *dst++ = *src++;
42            size -= 4;
43        }
[655]44    }
[425]45
46    unsigned char *cdst = (unsigned char*) dst;
47    unsigned char *csrc = (unsigned char*) src;
48
[586]49    while (size--) 
50    {
[425]51        *cdst++ = *csrc++;
52    }
53    return _dst;
54}
55
[653]56/********************************************************************
[425]57 * memset( _dst, value, size )
58 *
59 * Initialize memory buffers with predefined value.
60 *
61 * \param _dst   : Destination buffer base address
62 * \param value  : Initialization value
63 * \param size   : Number of bytes to initialize
64 *
[653]65 ********************************************************************/
[425]66void * memset(void *_dst, const int value, unsigned int size)
67{
[655]68    unsigned char val = (unsigned char) value;
69    int word = (val << 24) || (val << 16) ||
70               (val << 8 ) || (val      );
[425]71
[655]72    /*
73     * Write 4 bytes when destination buffer is aligned to 4 bytes
74     * and size is greater or equal to 4
75     */
76    unsigned int *dst = _dst;
77    if ( !((unsigned int)dst & 3) )
78    {
79        while (size > 3) 
80        {
81            *dst++ = word;
82            size -= 4;
83        }
84    }
[425]85
[655]86    /*
87     * Write 1 byte when destination buffer is not aligned to 4 bytes
88     * or size is smaller than 4
89     */
90    char* cdst = (char*) _dst;
91    while(size--)
92    {
93        *cdst++ = (char) value;
94    }
95
[425]96    return _dst;
97}
98
[653]99/********************************************************************
[586]100 * reset_print_elf_phdr( elf_phdr_ptr )
[425]101 *
102 * Print some fields of a ELF program header
103 *
104 * \param elf_phdr_ptr : Pointer to the ELF program header to print
105 *
[653]106 ********************************************************************/
[586]107void reset_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr)
[425]108{
[586]109    reset_puts("- type   : ");
110    reset_putx(elf_phdr_ptr->p_type);
[425]111
[586]112    reset_puts("\n- offset : ");
113    reset_putx(elf_phdr_ptr->p_offset);
[425]114
[586]115    reset_puts("\n- vaddr  : ");
116    reset_putx(elf_phdr_ptr->p_vaddr);
[425]117
[586]118    reset_puts("\n- paddr  : ");
119    reset_putx(elf_phdr_ptr->p_paddr);
[425]120
[586]121    reset_puts("\n- filesz : ");
122    reset_putx(elf_phdr_ptr->p_filesz);
[425]123
[586]124    reset_puts("\n- memsz  : ");
125    reset_putx(elf_phdr_ptr->p_memsz);
[425]126
[586]127    reset_puts("\n- flags  : ");
128    reset_putx(elf_phdr_ptr->p_flags);
[425]129
[586]130    reset_puts("\n- align  : ");
131    reset_putx(elf_phdr_ptr->p_align);
[425]132}
133
[653]134
135/********************************************************************
136 * reset_mcc_inval()
137 *
138 * Invalidate all data cache lines corresponding to a memory buffer
139 * (identified by an address and a size) in L2 cache.
140 ********************************************************************/
141#if USE_IOB
142void reset_mcc_invalidate ( const void * buffer,
143                            unsigned int size)
144{
145    unsigned int * mcc_address = (unsigned int *)MCC_PADDR_BASE;
146
147    // get the hard lock assuring exclusive access to MEMC
148    while (ioread32(&mcc_address[MCC_LOCK]));
149
150    // write invalidate paremeters on the memory cache this preloader
151    // use only the cluster 0 and then the HI bits are not used
152   
153    iowrite32(&mcc_address[MCC_ADDR_LO], (unsigned int) buffer);
154    iowrite32(&mcc_address[MCC_ADDR_HI], (unsigned int) 0);
155    iowrite32(&mcc_address[MCC_LENGTH] , (unsigned int) size);
156    iowrite32(&mcc_address[MCC_CMD]    , (unsigned int) MCC_CMD_INVAL);
157
158    // release the lock protecting MEMC
159    iowrite32(&mcc_address[MCC_LOCK], (unsigned int) 0);
160}
161#endif
162
163/********************************************************************
164 * reset_dcache_buf_invalidate()
165 *
166 * Invalidate all data cache lines corresponding to a memory buffer
167 * (identified by an address and a size) in L1 cache and L2 cache.
168 ********************************************************************/
169#if (CACHE_COHERENCE == 0) || USE_IOB
170void reset_buf_invalidate ( const void * buffer,
171                            unsigned int line_size,
172                            unsigned int size)
173{
174    unsigned int i;
175
176    // iterate on cache lines
177    for (i = 0; i <= size; i += line_size) 
178    {
179        asm volatile(
180            " cache %0, %1"
181            :// no outputs
182            :"i" (0x11), "R" (*((unsigned char *) buffer + i))
183            );
184    }
185
[655]186#if USE_IOB
187    reset_mcc_invalidate(buffer, size);
[653]188#endif
189}
190#endif
191
[425]192// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.