// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: ui_mem_cmds.cc
// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
// The above named program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License version 2 as published by the Free Software Foundation.
// The above named program is distributed in the hope that it will be
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
// You should have received a copy of the GNU General Public
// License along with this work; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
// ========== Copyright Header End ============================================
* Copyright (C) 2001 Sun Microsystems, Inc.
#pragma ident "@(#)1.19 07/11/19 ui_mem_cmds.cc"
typedef void* TM_OPAQUE_DATA
;
#include "blaze_globals.h"
///////////////////////////////////////////////////////////////////////
void load_elf64(char *filename
, uint64_t base_pa
, uint64_t base_va
);
static void load_elf64_section(Elf64_Shdr
*shdr
, Elf_Scn
*scn
,
uint64_t base_pa
, uint64_t base_va
);
///////////////////////////////////////////////////////////////////////
extern bool_t
schizo_rom_match (uint64_t paddr
);
extern bool_t
schizo_rom_store (uint32_t cpu_id
, uint64_t paddr
, uint32_t size
, uint64_t *buf
);
///////////////////////////////////////////////////////////////////////
int load_cmd(char *cp
, void *)
cp
= ui_parsew(cp
, &token
);
base_pa
= strtoll(token
, (char**)NULL
, 16);
cp
= ui_parsew(cp
, &filename
);
cp
= ui_parsew(cp
, &token
);
base_va
= strtoll(token
, (char**)NULL
, 16);
load_elf64(filename
, base_pa
, base_va
);
void load_elf64(char *filename
, uint64_t base_pa
, uint64_t base_va
)
/* Open the input file */
fd
= SYSTEM_open(filename
, O_RDONLY
);
ui
->error("<%s> not found \n", filename
);
/* Obtain the ELF descriptor */
(void) elf_version(EV_CURRENT
);
if ((elf
= elf_begin(fd
, ELF_C_READ
, NULL
)) == NULL
) {
ui
->error("%s\n", elf_errmsg(elf_errno()));
/* Obtain the .shstrtab data buffer */
if (((ehdr
= elf64_getehdr(elf
)) == NULL
) ||
((scn
= elf_getscn(elf
, ehdr
->e_shstrndx
)) == NULL
) ||
((data
= elf_getdata(scn
, NULL
)) == NULL
)) {
ui
->error("%s\n", elf_errmsg(elf_errno()));
/* Traverse input filename, looking for relevant sections */
for (cnt
= 1, scn
= NULL
; scn
= elf_nextscn(elf
, scn
); cnt
++) {
if ((shdr
= elf64_getshdr(scn
)) == NULL
) {
ui
->error("%s\n", elf_errmsg(elf_errno()));
if (strcmp((char *)data
->d_buf
+shdr
->sh_name
,
load_elf64_section(shdr
, scn
, base_pa
, base_va
);
} else if (strcmp((char *)data
->d_buf
+shdr
->sh_name
,
load_elf64_section(shdr
, scn
, base_pa
, base_va
);
} else if (strcmp((char *)data
->d_buf
+shdr
->sh_name
,
load_elf64_section(shdr
, scn
, base_pa
, base_va
);
} else if (strcmp((char *)data
->d_buf
+shdr
->sh_name
,
load_elf64_section(shdr
, scn
, base_pa
, base_va
);
} else if (strcmp((char *)data
->d_buf
+shdr
->sh_name
,
load_elf64_section(shdr
, scn
, base_pa
, base_va
);
///////////////////////////////////////////////////////////////
static void load_elf64_section(Elf64_Shdr
*shdr
, Elf_Scn
*scn
,
uint64_t base_pa
, uint64_t base_va
)
if ((data
= elf_getdata(scn
, NULL
)) == NULL
) {
ui
->error("%s\n", elf_errmsg(elf_errno()));
offset
= shdr
->sh_addr
- base_va
;
memwrite8u_blk_nl(mm1
, base_pa
+ offset
, (const unsigned char *)data
->d_buf
,
///////////////////////////////////////////////////////////////
bool_t
load_mem_image(const char * file
)
FILE * fp
= fopen (file
, "r");
while(fgets(s
, 512, fp
) != NULL
) {
pa
= strtoull(s
+1, NULL
, 16);
char * token
= strtok_r(s
, " \t\n", &last_s
);
if (token
== NULL
) continue;
uint64_t v
= strtoull(token
, NULL
, 16);
if (schizo_rom_match(pa
)) {
schizo_rom_store (0, pa
, 8, &v
);
memwrite64u_nl(mm1
, pa
, v
);
token
= strtok_r(NULL
, " \t\n", &last_s
);
} // bool_t load_mem_image(char * file)
bool_t
load_bin_image (char *file
, uint64_t addr
, uint64_t size
, uint64_t seg_size
, int zero_pad
, int create_lbl
)
bool_t is_ni_rom
= FALSE
;
is_ni_rom
= schizo_rom_match (addr
);
if (is_ni_rom
) { // If it is rom, it is special
ui
->output("ni rom: addr = 0x%llx, size = 0x%llx, seg_size = 0x%llx\n", addr
, size
, seg_size
);
for (int i
= 0; i
<seg_size
/8; i
++) {
schizo_rom_store (0, tmppa
, 8, &buf
);
FILE * Ffp
= fopen (file
, "r");
for (int i
=0; i
< size
/8; i
++) {
bytes_read
+= fread (&buf
, sizeof(uint64_t), 1, Ffp
);
schizo_rom_store (0, addr
, 8, &buf
);
while (size
- bytes_read
++) {
schizo_rom_store (0, addr
++, 1, &buf
);
ui
->output("total bytes to rom_store 0x%x\n", bytes_read
);
} else /* not ni rom */ {
FILE * fp
= fopen (file
, "r");
char s
[512]; // char *ps;
uint64_t pa
, buf
, last_pa
= 0;
buf8
= (uint8_t *)malloc(size
);
bytes_read
+= fread(buf8
, sizeof(uint8_t), size
, fp
);
memwrite8u_blk_nl(mm1
, addr
, (const unsigned char *)buf8
, (int)size
);
ui
->error("create_lbl not supported in this version. Please use v4.49 or prior\n");