source: trunk/softs/tsar_boot/src/boot_utils.c @ 584

Last change on this file since 584 was 425, checked in by cfuguet, 11 years ago

Modifications in tsar_boot:

  • Creating new files boot_utils.[c h] containing the memcpy, memset and some ELF format debug functions
  • Introducing assert in the boot_elf_loader to show an error when some of segments to load conflicts with some of the pre-loader segments
  • Cosmetic changes in boot_elf_loader to improve code readibility
  • Fixing bug in dcache_buf_invalidate function used by boot_ioc_read when cache coherence not supported. The condition in the for loop was erroneous.
  • Modification in Makefile: The SYSCLK_FREQ parameter is not passed anymore

as a Makefile parameter but it is definesd in the defs_platform.h file

File size: 2.1 KB
Line 
1/**
2 * \file    : boot_utils.c
3 * \date    : August 2012
4 * \author  : Cesar Fuguet
5 *
6 * Definition of some miscellaneous functions used in by the
7 * pre-loader
8 */
9
10#include <boot_utils.h>
11
12/**
13 * memcpy( _dst, _src, size )
14 *
15 * Transfer data between to memory buffers.
16 *
17 * \param _dst   : Destination buffer base address
18 * \param _src   : Source buffer base address
19 * \param size   : Number of bytes to transfer
20 *
21 */
22void * memcpy(void *_dst, const void *_src, unsigned int size)
23{
24    unsigned int *dst = _dst;
25    const unsigned int *src = _src;
26    if ( ! ((unsigned int)dst & 3) && ! ((unsigned int)src & 3) )
27        while (size > 3) {
28            *dst++ = *src++;
29            size -= 4;
30        }
31
32    unsigned char *cdst = (unsigned char*) dst;
33    unsigned char *csrc = (unsigned char*) src;
34
35    while (size--) {
36        *cdst++ = *csrc++;
37    }
38    return _dst;
39}
40
41/**
42 * memset( _dst, value, size )
43 *
44 * Initialize memory buffers with predefined value.
45 *
46 * \param _dst   : Destination buffer base address
47 * \param value  : Initialization value
48 * \param size   : Number of bytes to initialize
49 *
50 */
51void * memset(void *_dst, const int value, unsigned int size)
52{
53    char * dst = (char *) _dst;
54
55    while(size--) *dst++ = (char) value;
56
57    return _dst;
58}
59
60/*
61 * Misc functions for the ELF format
62 */
63
64/**
65 * boot_print_elf_phdr( elf_phdr_ptr )
66 *
67 * Print some fields of a ELF program header
68 *
69 * \param elf_phdr_ptr : Pointer to the ELF program header to print
70 *
71 */
72void boot_print_elf_phdr(Elf32_Phdr * elf_phdr_ptr)
73{
74    boot_puts("- type   : ");
75    boot_putx(elf_phdr_ptr->p_type);
76
77    boot_puts("\n- offset : ");
78    boot_putx(elf_phdr_ptr->p_offset);
79
80    boot_puts("\n- vaddr  : ");
81    boot_putx(elf_phdr_ptr->p_vaddr);
82
83    boot_puts("\n- paddr  : ");
84    boot_putx(elf_phdr_ptr->p_paddr);
85
86    boot_puts("\n- filesz : ");
87    boot_putx(elf_phdr_ptr->p_filesz);
88
89    boot_puts("\n- memsz  : ");
90    boot_putx(elf_phdr_ptr->p_memsz);
91
92    boot_puts("\n- flags  : ");
93    boot_putx(elf_phdr_ptr->p_flags);
94
95    boot_puts("\n- align  : ");
96    boot_putx(elf_phdr_ptr->p_align);
97}
98
99// vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab
Note: See TracBrowser for help on using the repository browser.