OpenCores
URL https://opencores.org/ocsvn/amber/amber/trunk

Subversion Repositories amber

[/] [amber/] [trunk/] [sw/] [boot-loader-ethmac/] [elfsplitter.c] - Blame information for rev 80

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 61 csantifort
/*----------------------------------------------------------------
2
//                                                              //
3
//  elfsplitter.c                                               //
4
//                                                              //
5
//  This file is part of the Amber project                      //
6
//  http://www.opencores.org/project,amber                      //
7
//                                                              //
8
//  Description                                                 //
9
//  Used by the boot loader to split an elf file and copy it    //
10
//  to the correct memory locations ready for execution.        //
11
//                                                              //
12
//  Author(s):                                                  //
13
//      - Conor Santifort, csantifort.amber@gmail.com           //
14
//                                                              //
15
//////////////////////////////////////////////////////////////////
16
//                                                              //
17
// Copyright (C) 2010 Authors and OPENCORES.ORG                 //
18
//                                                              //
19
// This source file may be used and distributed without         //
20
// restriction provided that this copyright statement is not    //
21
// removed from the file and that any derivative work contains  //
22
// the original copyright notice and the associated disclaimer. //
23
//                                                              //
24
// This source file is free software; you can redistribute it   //
25
// and/or modify it under the terms of the GNU Lesser General   //
26
// Public License as published by the Free Software Foundation; //
27
// either version 2.1 of the License, or (at your option) any   //
28
// later version.                                               //
29
//                                                              //
30
// This source is distributed in the hope that it will be       //
31
// useful, but WITHOUT ANY WARRANTY; without even the implied   //
32
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
33
// PURPOSE.  See the GNU Lesser General Public License for more //
34
// details.                                                     //
35
//                                                              //
36
// You should have received a copy of the GNU Lesser General    //
37
// Public License along with this source; if not, download it   //
38
// from http://www.opencores.org/lgpl.shtml                     //
39
//                                                              //
40
----------------------------------------------------------------*/
41
 
42
#include "amber_registers.h"
43
#include "address_map.h"
44
#include "utilities.h"
45
#include "line-buffer.h"
46
#include "timer.h"
47
#include "packet.h"
48 80 csantifort
#include "tcp.h"
49 61 csantifort
#include "telnet.h"
50
#include "elfsplitter.h"
51
 
52
 
53
 
54 80 csantifort
int elfsplitter (char* inbuf)
55 61 csantifort
{
56
   unsigned int i, j, k;
57
   ElfHeader*  elfHeader;
58
   Elf32_Shdr* elfSection;
59
   char *outbuf;
60
   unsigned int outP;
61
   int interrupt_table_written = 0;
62
   int interrupt_table_zero_written = 0;
63 78 csantifort
 
64 61 csantifort
   /* Create buffer to hold interrupt vector memory values
65
      Can't copy these into mem0 locations until ready to pass control
66
      t new program
67
   */
68
   elf_mem0_g = malloc(sizeof(mem_buf_t));
69
   for(i=0;i<MEM_BUF_ENTRIES;i++)
70
      elf_mem0_g->entry[i].valid = 0;
71 78 csantifort
 
72
 
73 61 csantifort
   elfHeader=(ElfHeader*)inbuf;
74
 
75
 
76
   if (strncmp((char*)elfHeader->e_ident+1,"ELF",3)) {
77
      return(1);
78
   }
79 78 csantifort
 
80 61 csantifort
   if (elfHeader->e_machine != 40) {
81 78 csantifort
      print_serial ("%s:L%d ERROR: ELF file not targetting correct processor type.\r\n",
82
            __FILE__, __LINE__);
83 61 csantifort
      return(1);
84
   }
85
 
86
 
87 78 csantifort
   for (i=0;i<elfHeader->e_shnum;++i) {
88
      elfSection=(Elf32_Shdr*)(inbuf+elfHeader->e_shoff+elfHeader->e_shentsize*i);
89
 
90
      /* section with non-zero bits, can be either text or data */
91
      if (elfSection->sh_type == SHT_PROGBITS && elfSection->sh_size != 0) {
92
         for (j=0; j<elfSection->sh_size; j++) {
93
            k = j + elfSection->sh_offset;
94
            outP         = elfSection->sh_addr + j;
95
 
96
            /* debug */
97
            if (outP >= ADR_EXEC_BASE)
98
               print_serial("%s:L%d ERROR: 1 outP value 0x%08x\r\n",__FILE__, __LINE__, outP);
99
            else if (outP > MEM_BUF_ENTRIES)
100
               outbuf[outP] = inbuf[k];
101
            else {
102
               elf_mem0_g->entry[outP].valid = 1;
103
               elf_mem0_g->entry[outP].data  = inbuf[k];
104 61 csantifort
               interrupt_table_written = 1;
105
               }
106 78 csantifort
         }
107
      }
108
 
109
      if (elfSection->sh_type == SHT_NOBITS && elfSection->sh_size != 0) {
110
         for (j=0; j<elfSection->sh_size; j++) {
111
            outP         = j + elfSection->sh_addr;
112
 
113
            /* debug */
114
            if (outP >= ADR_EXEC_BASE)
115
               print_serial("%s:L%d ERROR: 2 outP value 0x%08x\r\n",__FILE__, __LINE__, outP);
116
            else if (outP > MEM_BUF_ENTRIES)
117
               outbuf[outP] = 0;
118
            else {
119
               elf_mem0_g->entry[outP].valid = 1;
120
               elf_mem0_g->entry[outP].data  = 0;
121 61 csantifort
               interrupt_table_zero_written = 1;
122
               }
123 78 csantifort
         }
124
      }
125
   }
126
 
127 61 csantifort
   return 0;
128
}
129
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.