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

Subversion Repositories amber

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

Go to most recent revision | 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
#include "telnet.h"
49
#include "elfsplitter.h"
50
 
51
 
52
 
53
int elfsplitter (char* inbuf, socket_t* socket)
54
{
55
   unsigned int i, j, k;
56
   ElfHeader*  elfHeader;
57
   Elf32_Shdr* elfSection;
58
   char *outbuf;
59
   unsigned int outP;
60
   int interrupt_table_written = 0;
61
   int interrupt_table_zero_written = 0;
62 78 csantifort
 
63 61 csantifort
   /* Create buffer to hold interrupt vector memory values
64
      Can't copy these into mem0 locations until ready to pass control
65
      t new program
66
   */
67
   elf_mem0_g = malloc(sizeof(mem_buf_t));
68
   for(i=0;i<MEM_BUF_ENTRIES;i++)
69
      elf_mem0_g->entry[i].valid = 0;
70 78 csantifort
 
71
 
72 61 csantifort
   elfHeader=(ElfHeader*)inbuf;
73
 
74
 
75
   if (strncmp((char*)elfHeader->e_ident+1,"ELF",3)) {
76
      return(1);
77
   }
78 78 csantifort
 
79 61 csantifort
   if (elfHeader->e_machine != 40) {
80 78 csantifort
      print_serial ("%s:L%d ERROR: ELF file not targetting correct processor type.\r\n",
81
            __FILE__, __LINE__);
82 61 csantifort
      return(1);
83
   }
84
 
85
 
86 78 csantifort
   for (i=0;i<elfHeader->e_shnum;++i) {
87
      elfSection=(Elf32_Shdr*)(inbuf+elfHeader->e_shoff+elfHeader->e_shentsize*i);
88
 
89
      /* section with non-zero bits, can be either text or data */
90
      if (elfSection->sh_type == SHT_PROGBITS && elfSection->sh_size != 0) {
91
         for (j=0; j<elfSection->sh_size; j++) {
92
            k = j + elfSection->sh_offset;
93
            outP         = elfSection->sh_addr + j;
94
 
95
            /* debug */
96
            if (outP >= ADR_EXEC_BASE)
97
               print_serial("%s:L%d ERROR: 1 outP value 0x%08x\r\n",__FILE__, __LINE__, outP);
98
            else if (outP > MEM_BUF_ENTRIES)
99
               outbuf[outP] = inbuf[k];
100
            else {
101
               elf_mem0_g->entry[outP].valid = 1;
102
               elf_mem0_g->entry[outP].data  = inbuf[k];
103 61 csantifort
               interrupt_table_written = 1;
104
               }
105 78 csantifort
         }
106
      }
107
 
108
      if (elfSection->sh_type == SHT_NOBITS && elfSection->sh_size != 0) {
109
         for (j=0; j<elfSection->sh_size; j++) {
110
            outP         = j + elfSection->sh_addr;
111
 
112
            /* debug */
113
            if (outP >= ADR_EXEC_BASE)
114
               print_serial("%s:L%d ERROR: 2 outP value 0x%08x\r\n",__FILE__, __LINE__, outP);
115
            else if (outP > MEM_BUF_ENTRIES)
116
               outbuf[outP] = 0;
117
            else {
118
               elf_mem0_g->entry[outP].valid = 1;
119
               elf_mem0_g->entry[outP].data  = 0;
120 61 csantifort
               interrupt_table_zero_written = 1;
121
               }
122 78 csantifort
         }
123
      }
124
   }
125
 
126 61 csantifort
   return 0;
127
}
128
 

powered by: WebSVN 2.1.0

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