Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / system / tracemod / tm_cpu_ext.cc
CommitLineData
920dae64
AT
1// ========== Copyright Header Begin ==========================================
2//
3// OpenSPARC T2 Processor File: tm_cpu_ext.cc
4// Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
5// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
6//
7// The above named program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public
9// License version 2 as published by the Free Software Foundation.
10//
11// The above named program is distributed in the hope that it will be
12// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14// General Public License for more details.
15//
16// You should have received a copy of the GNU General Public
17// License along with this work; if not, write to the Free Software
18// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
19//
20// ========== Copyright Header End ============================================
21/*
22 * Copyright (C) 1991, 2001 Sun Microsystems, Inc.
23 * All rights reserved.
24 */
25#pragma ident "@(#)1.4 01/11/06 tm_blaze_ext.cc"
26
27/*
28 * Copyright (c) 1989, Sun Microsystems, Inc. All Rights Reserved. Sun
29 * considers its source code as an unpublished, proprietary trade secret, and
30 * it is available only under strict license provisions. This copyright
31 * notice is placed here only to protect Sun in the event the source is
32 * deemed a published work. Disassembly, decompilation, or other means of
33 * reducing the object code to human readable form is prohibited by the
34 * license agreement under which this code is provided to the user or company
35 * in possession of this copy
36 *
37 * RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the
38 * Government is subject to restrictions as set forth in subparagraph
39 * (c) (1) (ii) of the Rights in Technical Data and Computer Software clause
40 * at DFARS 52.227-7013 and in similar clauses in the FAR and NASA FAR
41 * Supplement
42 */
43
44#include <sys/types.h>
45#include <assert.h>
46#include <stdio.h>
47#include <stdlib.h>
48#include <string.h>
49#include <synch.h>
50#include <dlfcn.h>
51
52#include "types.h"
53#include "blaze_globals.h"
54#include "cpu_interface.h"
55#include "system.h"
56
57typedef void* TM_OPAQUE_DATA;
58#include "tracemod.h"
59
60#include "mmi.h"
61
62#include "ui.h"
63#include "tm_impl.h"
64
65static tracemod_t *pTm_ASI_ext = NULL;
66
67// say there are 1024 possible asi's (including room for future growth).
68// we declare an array of modules, indexed by the ASI, for quick access
69
70static const int N_ASI = 1024;
71
72static tracemod_t *asi_modules [N_ASI];
73static int asi_modules_cnt = 0;
74
75static tracemod_t * asi2module[N_ASI] = {0};
76static mmi_ld_asi_action asi2ldhandler[N_ASI] = {0};
77static mmi_st_asi_action asi2sthandler[N_ASI] = {0};
78
79/////////////////////////////////////////////////////////////
80
81bool_t add_asi_module (tracemod_t* mod, uint32_t asi, mmi_ld_asi_action ld_handler, mmi_st_asi_action st_handler)
82{
83 if (asi2module[asi] != NULL) {
84 if (mod != asi2module[asi]) {
85 ui->error("loading asi module %s: a module (%s) for asi %d is already loaded\n",
86 mod->name, asi2module[asi]->name, asi);
87 return FALSE;
88 } else {
89 return TRUE;
90 }
91 }
92
93 int ii = 0;
94
95 for (ii = 0; ii < asi_modules_cnt; ii++) {
96 if (asi_modules[ii] == mod) {
97 // module is already loaded, but for some other ASI
98 break;
99 }
100 }
101
102 if (ii == asi_modules_cnt) {
103 // new module
104
105 if (asi_modules_cnt >= N_ASI) {
106 ui->error("loading asi module %s: too many ASI modules (%d) already loaded\n",
107 mod->name, N_ASI);
108 return FALSE;
109 }
110
111 asi_modules[asi_modules_cnt++] = mod;
112 }
113
114 asi2module[asi] = mod;
115 asi2ldhandler[asi] = ld_handler;
116 asi2sthandler[asi] = st_handler;
117
118 return TRUE;
119}
120
121/////////////////////////////////////////////////////////////
122
123// TODO : to make it more accurate
124//
125// ASI handling :
126// Assume we have CPU (CPUM) and DEVICE module (DEVM) responsible for some extra ASI handling.
127// 1. DEVM registers ASI handler with "mmi_register_asi...." with BLAZE
128// 2. RS2BLAZE "glue code" registers it's own ASI callback with CPUM
129// 3. When CPUM executes say LD with unsopported ASI it INVOKES callback (see #2)
130// 4. This callback in turn invokes TM_execute_load/store_asi (see below).
131//
132
133int
134TM_execute_load_asi (uint32_t asi, uint64_t vaddr, uint64_t *buf, int size, uint32_t cpuid)
135{
136
137 tracemod_t * mod = asi2module[asi];
138 if (mod == NULL) return -1;
139
140 mmi_ld_asi_action ld_handler = asi2ldhandler[asi];
141 if (ld_handler == NULL) {
142 return -1;
143 }
144
145 return ld_handler(TM_get_asi_client_data((void*)mod), asi, vaddr, buf, size, cpuid);
146
147}
148
149/////////////////////////////////////////////////////////////
150
151int
152TM_execute_store_asi (uint32_t asi, uint64_t vaddr, uint64_t *buf, int size, uint32_t cpuid)
153{
154
155 tracemod_t * mod = asi2module[asi];
156 if (mod == NULL) return -1;
157
158 mmi_st_asi_action st_handler = asi2sthandler[asi];
159 if (st_handler == NULL) {
160 return -1;
161 }
162
163 return st_handler(TM_get_asi_client_data((void*)mod), asi, vaddr, *buf, size, cpuid);
164}