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

Last change on this file since 620 was 586, checked in by alain, 11 years ago

Modify the name "boot" to "reset" to avoid confusion
between the pre-loader and the boot-loader...
Increase the size of the segment containing the stacks.

File size: 2.6 KB
Line 
1/**
2 * \file    : reset_utils.c
3 * \date    : August 2012
4 * \author  : Cesar Fuguet
5 *
6 * Definition of utilities functions used by the TSAR pre-loader
7 */
8
9#include <reset_utils.h>
10
11/*****************************************
12 * proctime()
13 *
14 * Returns processor local time.
15 ****************************************/
16inline unsigned int proctime() 
17{
18    unsigned int ret;
19    asm volatile ("mfc0   %0,        $9":"=r" (ret));
20    return ret;
21}
22
23/*****************************************
24 * memcpy( _dst, _src, size )
25 *
26 * Transfer data between two memory buffers.
27 *
28 * \param _dst   : Destination buffer base address
29 * \param _src   : Source buffer base address
30 * \param size   : Number of bytes to transfer
31 *
32 ****************************************/
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) )
38        while (size > 3) 
39        {
40            *dst++ = *src++;
41            size -= 4;
42        }
43
44    unsigned char *cdst = (unsigned char*) dst;
45    unsigned char *csrc = (unsigned char*) src;
46
47    while (size--) 
48    {
49        *cdst++ = *csrc++;
50    }
51    return _dst;
52}
53
54/*****************************************
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 *
63 ****************************************/
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
73/*****************************************
74 * reset_print_elf_phdr( elf_phdr_ptr )
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 *
80 ****************************************/
81void reset_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr)
82{
83    reset_puts("- type   : ");
84    reset_putx(elf_phdr_ptr->p_type);
85
86    reset_puts("\n- offset : ");
87    reset_putx(elf_phdr_ptr->p_offset);
88
89    reset_puts("\n- vaddr  : ");
90    reset_putx(elf_phdr_ptr->p_vaddr);
91
92    reset_puts("\n- paddr  : ");
93    reset_putx(elf_phdr_ptr->p_paddr);
94
95    reset_puts("\n- filesz : ");
96    reset_putx(elf_phdr_ptr->p_filesz);
97
98    reset_puts("\n- memsz  : ");
99    reset_putx(elf_phdr_ptr->p_memsz);
100
101    reset_puts("\n- flags  : ");
102    reset_putx(elf_phdr_ptr->p_flags);
103
104    reset_puts("\n- align  : ");
105    reset_putx(elf_phdr_ptr->p_align);
106}
107
108// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.