[425] | 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 | */ |
---|
| 22 | void * 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 | */ |
---|
| 51 | void * 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 | */ |
---|
| 72 | void 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 |
---|