[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 | |
---|
[586] | 11 | /***************************************** |
---|
| 12 | * proctime() |
---|
| 13 | * |
---|
| 14 | * Returns processor local time. |
---|
| 15 | ****************************************/ |
---|
| 16 | inline unsigned int proctime() |
---|
| 17 | { |
---|
| 18 | unsigned int ret; |
---|
| 19 | asm volatile ("mfc0 %0, $9":"=r" (ret)); |
---|
| 20 | return ret; |
---|
| 21 | } |
---|
| 22 | |
---|
| 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 | * |
---|
[586] | 32 | ****************************************/ |
---|
[425] | 33 | void * 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 | |
---|
[586] | 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 | * |
---|
[586] | 63 | ****************************************/ |
---|
[425] | 64 | void * 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 | |
---|
[586] | 73 | /***************************************** |
---|
| 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 | * |
---|
[586] | 80 | ****************************************/ |
---|
| 81 | void 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 | |
---|
| 108 | // vim: tabstop=4 : softtabstop=4 : shiftwidth=4 : expandtab |
---|