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

Subversion Repositories amber

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

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
 
63
 
64
   /* 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
 
72
 
73
   elfHeader=(ElfHeader*)inbuf;
74
 
75
 
76
   if (strncmp((char*)elfHeader->e_ident+1,"ELF",3)) {
77
      return(1);
78
   }
79
 
80
   if (elfHeader->e_machine != 40) {
81
      telnet_broadcast ("%s ERROR: ELF file not targetting correct processor type.\r\n",
82
            __func__);
83
      return(1);
84
   }
85
 
86
 
87
   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
               telnet_broadcast("%s ERROR: 1 outP value 0x%08x\r\n",__func__, 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
               interrupt_table_written = 1;
105
               }
106
         }
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
               telnet_broadcast("%s ERROR: 2 outP value 0x%08x\r\n",__func__, 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
               interrupt_table_zero_written = 1;
122
               }
123
         }
124
      }
125
   }
126
 
127
/*
128
   if (interrupt_table_written)
129
      telnet_broadcast ("%s WARNING: Interrupt table writes\r\n",__func__);
130
   if (interrupt_table_zero_written)
131
      telnet_broadcast ("%s WARNING: Interrupt table ZERO writes\r\n",__func__);
132
*/
133
   return 0;
134
}
135
 

powered by: WebSVN 2.1.0

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