// ========== Copyright Header Begin ==========================================
// OpenSPARC T2 Processor File: rom.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 ============================================
* fake rom device for T1 in blaze/SAM
* Copyright (c) 2004 by Sun Microsystems, Inc.
#include <sys/syscall.h> // get exec number
#include <sys/types.h> // uid_t
#include <unistd.h> // getuid()
extern "C" int rom_access(uint32_t cpuid
, void* obj
, uint64_t paddr
, mmi_bool_t wr
, uint32_t size
, uint64_t* buf
, uint8_t bytemask
);
int rom_ld_operation (void *cd
, uint64_t paddr
, uint64_t *buf
, int sz
, uint32_t cpuid
);
int rom_st_operation (void *cd
, uint64_t paddr
, uint64_t *buf
, int sz
, uint32_t cpuid
);
extern "C" void rom_create_instance (const char *modname
, const char *instance_name
);
if (! mmi_register_instance_creator("rom", rom_create_instance
) ) {
ui
->error("Cannot register instance creator for rom\n");
void rom_create_instance (const char *modname
, const char *instance_name
)
sam_rom_s
* rom_obj
= new sam_rom_s
;
mmi_instance_t instance
= mmi_register_instance(modname
, instance_name
, (void *) &rom_obj
, "rom dummy device");
// expected syntax: sysconf rom rom1 startpa=<0xblah> endpa=<0xblah>
int argc
= mmi_argc(instance
);
char * arg
= strdup(mmi_argv(instance
, i
));
char * lv
= strtok_r(arg
, "=", &marker
);
if (strcmp(lv
, "startpa") == 0) {
char * rv
= strtok_r(NULL
, "=", &marker
);
rom_obj
->startpa
= strtoull(rv
, NULL
, 0);
perror("rom: error parsing startpa");
} else if (strcmp(lv
, "endpa") == 0) {
char * rv
= strtok_r(NULL
, "=", &marker
);
rom_obj
->endpa
= strtoull(rv
, NULL
, 0);
perror("rom: error parsing startpa");
ui
->error("%s - unknown parameter of rom device %s\n",lv
,instance_name
);
rom_obj
->sz
= rom_obj
->endpa
- rom_obj
->startpa
+ 1;
if (mmi_map_physio(rom_obj
->startpa
, rom_obj
->sz
, (void *) rom_obj
, rom_access
)) {
ui
->error("rom: unable to register IO interceptor\n");
int rom_access(uint32_t cpuid
, void* obj
, uint64_t paddr
, mmi_bool_t wr
, uint32_t size
, uint64_t* buf
, uint8_t bytemask
)
return rom_st_operation(obj
, paddr
, buf
, size
, cpuid
);
return rom_ld_operation(obj
, paddr
, buf
, size
, cpuid
);
int rom_ld_operation (void *obj
, uint64_t paddr
, uint64_t *buf
, int size
, uint32_t cpuid
)
// redirect load to access sparse mem
case 1: *buf
= memread8u (mm1
, paddr
); break;
case 2: *buf
= memread16u (mm1
, paddr
); break;
case 4: *buf
= memread32u (mm1
, paddr
); break;
case 8: *buf
= memread64u (mm1
, paddr
); break;
ui
->error("rom: ld_operation pa 0x%llx size %d cpu %d, ignored\n",
} // int rom_ld_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t cpuid)
int rom_st_operation (void *obj
, uint64_t paddr
, uint64_t *buf
, int size
, uint32_t cpuid
)
// redirect store to access sparse mem
case 1: memwrite8u (mm1
, paddr
, *buf
); break;
case 2: memwrite16u (mm1
, paddr
, *buf
); break;
case 4: memwrite32u (mm1
, paddr
, *buf
); break;
case 8: memwrite64u (mm1
, paddr
, *buf
); break;
ui
->error("rom: st_operation pa 0x%llx size %d cpu %d, ignored\n",
} // int rom_st_operation (void *cd, uint64_t paddr, uint64_t *buf, int size, uint32_t cpuid)
/////////////////////////////////////////////////
/////////////////////////////////////////////////