Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / include / vcpu.h
CommitLineData
920dae64
AT
1/*
2* ========== Copyright Header Begin ==========================================
3*
4* OpenSPARC T2 Processor File: vcpu.h
5* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
7*
8* The above named program is free software; you can redistribute it and/or
9* modify it under the terms of the GNU General Public
10* License version 2 as published by the Free Software Foundation.
11*
12* The above named program is distributed in the hope that it will be
13* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15* General Public License for more details.
16*
17* You should have received a copy of the GNU General Public
18* License along with this work; if not, write to the Free Software
19* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20*
21* ========== Copyright Header End ============================================
22*/
23///////////////////////////////////////////////////////////
24//
25// File: vcpu.h
26//
27// Copyright (C) 2005 Sun Microsystems, Inc.
28// All rights reserved.
29//
30
31
32#ifndef _CPU_LIB_INTERFACE_H
33#define _CPU_LIB_INTERFACE_H
34
35#include <stdlib.h>
36
37// #include "vtracer.h"
38
39// This file defines interface structures for the cpu module
40// in the shared library.
41
42// A few instances of cpu objects could be created,
43// each cpu object may have a few cpu cores, each core may
44// have a few strands.
45// Cpu cores could run on separate threads of the host machine.
46
47
48// max number of Cpu's supported
49const int NCPU_MAX = 1024;
50
51
52
53//
54// Supported implementations
55//
56// Bit encoding:
57// 0..7 mask rev of chip;
58// 8..23 cpu implementation;
59// 24..31 sim implementation;
60//
61typedef enum
62{
63 VCPU_IMPL_VER_NONE = 0,
64
65 VCPU_IMPL_VER_SPITFIRE = 0x00001000,
66 VCPU_IMPL_VER_BLACKBIRD = 0x00001100,
67 VCPU_IMPL_VER_SABRE = 0x00001200,
68 VCPU_IMPL_VER_SAPPHIRE = 0x00001300,
69 VCPU_IMPL_VER_CHEETAH = 0x00001400,
70 VCPU_IMPL_VER_CHPLUS = 0x00001500,
71 VCPU_IMPL_VER_SUN4U = 0x00001000,
72
73 VCPU_IMPL_VER_N1 = 0x00002300,
74 VCPU_IMPL_VER_N2 = 0x00002410,
75 VCPU_IMPL_VER_SUN4V = 0x00002000,
76 VCPU_IMPL_VER_MASK = 0x00ffffff,
77
78 VCPU_IMPL_SIM_BLAZE = 0x01000000,
79 VCPU_IMPL_SIM_RIESLING = 0x02000000,
80 VCPU_IMPL_SIM_VONK = 0x03000000,
81 VCPU_IMPL_SIM_MASK = 0xff000000
82}
83VCPU_Type;
84
85/////////////////////////////////////////////////////
86//
87// Cpu config structure
88//
89
90
91typedef class
92{
93public:
94 char *name; // cpu instance name
95 char *type; // Ultrasparc-T1, ...
96 char *mmu_type; // t1, ...
97
98 VCPU_Type cpu_type; // encoded cpu impl version
99
100
101 int reg_wins; // number of reg windows
102 int tl_max; // trap level max
103
104 int itlb_size; // number of tlb entries
105 int dtlb_size;
106
107
108 int loopticks; // number of instruction completed before incrementing stick reg
109 int stickincr; // the amount stick has to be incremented
110
111 uint64_t cpufreq; // cpu clock
112 uint64_t stickfreq; // system clock
113
114 double cpi; // cycles per instruction
115
116 int delay; // delay this number of instructions
117
118 int mode; // 1 - multithreaded (MP on MP) run;
119 // 0 - all cpu's on a single thread;
120
121 int trace_on; // 1 - trace enabled;
122 // 0 - trace disabled;
123
124 int execution_driven; // must be updated using the get/enable/disable functions
125
126
127 // a platform dependent id by which a "strand" can be referred to
128 // by the operating system or system bus devices. For a ch/ch+ platform
129 // the "strand" is the cpu itself, and id would be the agent id of the cpu
130 // on the safari bus. For a sun4v implementation, the id would be the
131 // strand id of the strand. The typical usage of this id is to identify
132 // the vcpu that is a target of a cpu cross call or device mondo interrupt.
133 // the value either comes from cpu sysconf line or an implementation
134 // may choose to provide one automatically.
135 int id;
136
137}
138VCPU_Config;
139
140
141
142
143
144
145/////////////////////////////////////////////////////
146//
147// Interrupt message
148//
149#define INTR_DATA_SIZE 8
150
151struct VCPU_InterruptRequest
152{
153 int isid; // interrupt sender ID
154 int itid; // interrupt target ID
155
156 uint64_t data[INTR_DATA_SIZE]; // (sun4u only?) data
157
158 uint32_t bogus_src_dev_id; // aka INO, ie interrupt number ???
159
160 uint32_t bogus_src_dev_type; // bogus debug info
161};
162
163
164
165
166
167
168/////////////////////////////////////////////////////
169//
170// Cpu imported interface for the io and memory
171// subsystem
172//
173// Set of function pointers that cpu module calls
174// to send a request to the system modules.
175//
176
177enum VCPU_Operation
178{
179 VCPU_LOAD_OP, // Load 1,2, or more bytes from memory. Atomicity is guaranteed up to 8 bytes
180 VCPU_STORE_OP, // Store 1,2, or more bytes to memory. Atomicity is guaranteed up to 8 bytes
181 VCPU_STORE_PARTIAL_OP, // Store 1,2, or more bytes to memory, bit enabled by set bits
182 VCPU_LOAD_ATOMIC_OP, // Load atomic. Atomicity of the load is guaranteed
183 VCPU_SWAP_OP, // Swap - SunSparc 32bit swap instruction
184 VCPU_CAS_OP, // Compare And Swap - SunSparc 32bit casa, or 64bit casxa instruction
185 VCPU_LDSTUB_OP, // LoaD STore Unsigned Byte - SunSparc 8bit ldstub instruction
186 VCPU_PREFETCH_OP, // Prefetch data into the cache hierarchy
187 VCPU_FLUSH_OP, // Flush data in the cache hierarchy to memory
188 VCPU_PEEK_OP, // Read data from memory mapped registers without causing sideeffect
189 VCPU_POKE_OP // Write data to memory mapped registers without causing sideeffect
190};
191
192class SMemory; // forward declarations
193class VTracer;
194
195typedef struct
196{
197 // memory interface
198 class SMemory *mem;
199
200
201 // vtracer interface
202 class VTracer *vtrace;
203
204 // io interface
205 int (*access_io)
206 (
207 int vcpu_id, // cpu id
208 int operation, // operation code
209 uint64_t paddr, // physical address
210 uint32_t size, // access size
211 uint64_t &data, // 64 bit value to read/write
212 uint64_t bytemask // access byte mask
213 );
214
215 // interface to access devices that mapped to asi ring
216 int (*access_asi)
217 (
218 int vcpu_id, // cpu id
219 int operation, // operation code
220 uint32_t asi, // asi value
221 uint64_t vaddr, // virtual address
222 int32_t size, // access size
223 uint64_t &buf // 64 bit data value
224 );
225
226 // serial device for software bring up debugging
227 int (*access_serial)
228 (
229 uint8_t *c, // character to read/write
230 int wr // 0 - read, 1 - write
231 );
232}
233VCPU_ImpIntf;
234
235
236
237
238/////////////////////////////////////////////////////
239//
240// Cpu module exported interface
241//
242// when applicable return 0- if succeed, >0- if fail.
243//
244
245typedef struct
246{
247
248 // create/config method
249 // return vcpu pointer
250 void * (*create ) // new cpu module
251 (
252 VCPU_Config *cinfo, // cpu config params
253 VCPU_ImpIntf *intf // interface to the system
254 );
255
256 int (*reset ) ( uint64_t pc );
257
258 int (*destroy) ();
259
260 // set/get config param
261 int (*exec_cmd)
262 (
263 char *cmd_str, // command string
264 char *reply, // return reply string
265 int reply_size // size of reply string
266 );
267
268 // save restore methods
269 int (*save ) ( char *dir_name );
270 int (*restore) ( char *dir_name );
271
272 // advance nn number of cycles
273 int (*cycle ) ( uint64_t nn );
274
275
276}
277VCPU_ExInterface;
278
279
280////////////////////////////////////////////////////////
281//
282// Get exported interface from the cpu shared library.
283//
284// Assign function pointers in the interface structure.
285//
286//
287// return: 0 - success; 1 - fail;
288
289extern "C" int get_ex_interface
290(
291 VCPU_ExInterface *intf // pointer to the interface structure
292);
293
294
295typedef int (*VCPU_GetIntfFn )( VCPU_ExInterface *intf );
296
297
298// breakpoint type
299typedef enum
300{
301 VCPU_BP_INSTR_ADDR = 0,
302 VCPU_BP_TRAP,
303 VCPU_BP_RED,
304 VCPU_BP_DATA_READ_ADDR,
305 VCPU_BP_DATA_WRITE_ADDR,
306 VCPU_BP_OPCODE,
307 VCPU_N_BP_TYPES
308}
309VCPU_BpType;
310
311
312// This enum is used to access cpu register state through vcpu's
313// get_reg/set_reg methods.
314enum
315{
316 VCPU_IRF_0 = 0x00,
317 VCPU_DRF_0 = 0x20,
318 VCPU_ASR_0 = 0x40,
319 VCPU_PR_0 = 0x60,
320 VCPU_HPR_0 = 0x80,
321 VCPU_SIM_0 = 0xA0,
322 VCPU_FRF_0 = 0xC0,
323
324 VCPU_MAX_INDEX = VCPU_FRF_0 + 0x1f,
325
326 VCPU_ASR_Y = VCPU_ASR_0,
327 VCPU_ASR_CCR = VCPU_ASR_0 + 2,
328 VCPU_ASR_ASI = VCPU_ASR_0 + 3,
329 VCPU_ASR_TICK = VCPU_ASR_0 + 4,
330 VCPU_ASR_PC = VCPU_ASR_0 + 5,
331 VCPU_ASR_FPRS = VCPU_ASR_0 + 6,
332 VCPU_ASR_PCR = VCPU_ASR_0 + 16,
333 VCPU_ASR_PIC = VCPU_ASR_0 + 17,
334 VCPU_ASR_IEU_CNTRL = VCPU_ASR_0 + 18,
335 VCPU_ASR_GSR = VCPU_ASR_0 + 19,
336 VCPU_ASR_SOFTINT_SET= VCPU_ASR_0 + 20,
337 VCPU_ASR_SOFTINT_CLR= VCPU_ASR_0 + 21,
338 VCPU_ASR_SOFTINT = VCPU_ASR_0 + 22,
339 VCPU_ASR_TICK_CMPR = VCPU_ASR_0 + 23,
340 VCPU_ASR_STICK = VCPU_ASR_0 + 24,
341 VCPU_ASR_STICK_CMPR = VCPU_ASR_0 + 25,
342
343 VCPU_PR_TPC = VCPU_PR_0 + 0,
344 VCPU_PR_TNPC = VCPU_PR_0 + 1,
345 VCPU_PR_TSTATE = VCPU_PR_0 + 2,
346 VCPU_PR_TT = VCPU_PR_0 + 3,
347 VCPU_PR_TICK = VCPU_PR_0 + 4,
348 VCPU_PR_TBA = VCPU_PR_0 + 5,
349 VCPU_PR_PSTATE = VCPU_PR_0 + 6,
350 VCPU_PR_TL = VCPU_PR_0 + 7,
351 VCPU_PR_PIL = VCPU_PR_0 + 8,
352 VCPU_PR_CWP = VCPU_PR_0 + 9,
353 VCPU_PR_CANSAVE = VCPU_PR_0 + 10,
354 VCPU_PR_CANRESTORE = VCPU_PR_0 + 11,
355 VCPU_PR_CLEANWIN = VCPU_PR_0 + 12,
356 VCPU_PR_OTHERWIN = VCPU_PR_0 + 13,
357 VCPU_PR_WSTATE = VCPU_PR_0 + 14,
358 VCPU_PR_FPQ = VCPU_PR_0 + 15, // depricated after USIII
359 VCPU_PR_GL = VCPU_PR_0 + 16,
360 VCPU_PR_VER = VCPU_PR_0 + 31, // depricated after USIII (replaced by HVER)
361
362 VCPU_HPR_HPSTATE = VCPU_HPR_0 + 0,
363 VCPU_HPR_HTSTATE = VCPU_HPR_0 + 1,
364
365 VCPU_ASR_NPC = VCPU_SIM_0 + 0,
366 VCPU_ASR_FSR = VCPU_SIM_0 + 1,
367
368 VCPU_SIM_MAX_GL = VCPU_SIM_0 + 6,
369 VCPU_SIM_MAX_TL = VCPU_SIM_0 + 4,
370 VCPU_SIM_MAX_WP = VCPU_SIM_0 + 3
371};
372
373/////////////////////////////////////////////////////////////
374//
375// Vcpu hides the details of the cpu specific implementation.
376// It presents an abstract interface to the "virtual cpu" -
377// for cpu with multiple strands it represents each strands;
378// for cpu without strands it represent the cpu.
379
380typedef int (*VCPU_BpActionFn)( int bp_id, int vcpu_id );
381
382class Vcpu
383{
384 public:
385
386 VCPU_Config config;
387 VCPU_ImpIntf sys_intf;
388
389
390 public:
391
392 // virtual interface methods,
393 // when applicable return 0- success, >0- fail;
394
395 virtual int reconfig (VCPU_Config conf) { return 0; }
396
397
398 // "unique" platform dependent id of a cpu. eg in case of ch/ch+, the
399 // id is same as the agent id if the cpu. In case of N1/N2, etc,
400 // the id is the threadid of the strand. The id is the one that is to
401 // be used for cpu cross calls and identifying cpu target for device
402 // interrupts. Typically the function Vcpu *get_vcpu(int id),
403 // defined in cpu_interface.h is used to get the target Vcpu pointer
404 // given its id. The id's may or may not by contiguous, it is
405 // derived from cpu sysconf parameter "id". If the parameter is
406 // not present, then id is assigned in sequential order.
407 //
408 virtual int id() { return config.id; }
409
410
411 // step n number of instructions;
412 // each Vcpu can be called from a separate working thread of
413 // the host machine;
414 // Vcpu that belongs to the same core may need to be on the
415 // same working thread to reduce locking for mt safe calls
416 //
417 virtual int stepi ( int64_t n=1 )=0;
418
419
420 // signal an interrupt
421 virtual int interrupt ( VCPU_InterruptRequest *signal )=0;
422
423
424 virtual void update_stick(int64_t stickincr) = 0;
425
426 // HW performance instrumentation counters
427 // CH and NI have just two counters, we will extend this enum
428 // as needed when we implement xx, etc...
429 //
430 typedef enum {PIC0, PIC1} perfcntr;
431 //
432 virtual void update_perfcntr(perfcntr which, int64_t incr) = 0;
433
434 // debugger/frontend methods
435
436 typedef int RegIndex;
437
438 enum RegError
439 {
440 REG_OK, // All OK
441 REG_NOT_AVAILABLE, // Register name or index is not available.
442 REG_VALUE_OUT_OF_RANGE // Value written is not accepted
443 };
444
445 virtual RegError get_reg_index( const char* reg_name, RegIndex* index ) = 0;
446 virtual const char* get_reg_name( RegIndex index ) = 0;
447
448 // get_reg() and set_reg() read and write the vcpu registers
449 // such as window regs like %i2, globals like %g0, asr like
450 // %asr13, privileged like %tl, hyperprivileged like %htstate,
451 // unmapped state like %npc and %fsr, etc.
452
453 virtual RegError get_reg( RegIndex index, uint64_t* value ) = 0;
454 virtual RegError set_reg( RegIndex index, uint64_t value ) = 0;
455
456 // asi mapped regs
457 virtual int get_asi(uint8_t asi, uint64_t addr, uint64_t &data) = 0;
458 virtual int set_asi(uint8_t asi, uint64_t addr, uint64_t data) = 0;
459
460 // The TranslateMode enumeration is for translate() interfaces
461 // that takes an address and converts it into an physical address.
462 // The enumeration tells the translate() method of the vcpu
463 // api which arguments are valid and how to interpret the
464 // input address: VA virtual, RA real, PA phisical
465
466 enum TranslateMode
467 {
468 TRANSLATE_VA_TO_PA, // VA to PA with processor context and partitionid
469 TRANSLATE_VA_TO_PA_CTX, // VA to PA with given context and processor partitionid
470 TRANSLATE_VA_TO_PA_CTX_PID, // VA to PA with given context and partitionid
471 TRANSLATE_RA_TO_PA, // RA to PA with processor partitionid
472 TRANSLATE_RA_TO_PA_PID, // RA to PA with given partitionid
473 TRANSLATE_PA_TO_PA // PA (64bit) to PA (processor specific width)
474 };
475
476 // The TranslateError enum is for errors returned by translate()
477
478 enum TranslateError
479 {
480 TRANSLATE_OK, // phys_addr argument to translate conmtains phys addr
481 TRANSLATE_NO_TTE_FOUND // translate() cound not find matching TTE to get phys addr
482 };
483
484 // If translate() returns TRANSLATE_OK then the translation was successful. Else
485 // the translation cannot be completed with the parameters given for the particular mode.
486
487 virtual TranslateError translate( TranslateMode mode, uint64_t addr, uint64_t context, uint64_t partitionid, uint64_t* phys_addr ) = 0;
488
489 // caller must explicitly FREE return_array before it is overwritten or goes out of scope
490 virtual int get_tlb_entries(struct TLBInfo * &return_array) = 0;
491
492 // mem read - used if caches or write buffer is present;
493 // address could be virtuall or physical;
494 // little or big endian access is defined by current state;
495 virtual int read_mem
496 (
497 uint64_t addr, // byte address
498 uint64_t *value, // value to load
499 int size, // number of bytes
500 int asi= 0x82, // ASI_PRIMARY_NO_FAULT
501 int is_physical=0 // 1-physical address, 0-virtual address
502 )=0;
503
504 // mem write
505 virtual int write_mem
506 (
507 uint64_t addr, // byte address
508 uint64_t value, // value to write
509 int size, // number of bytes
510 int asi=0x82, // ASI_PRIMARY_NO_FAULT
511 int is_physical=0 // 1-physical address, 0-virtual address
512 )=0;
513
514 // set breakpoint;
515 // when breakpoint hits - instruction should not be commited
516 virtual int set_breakpoint
517 (
518 int *bp_id, // return breakpoint id;
519 VCPU_BpType type, // breakpoint type
520 uint64_t value, // opcode, instruction or data address
521 VCPU_BpActionFn action,// call this function on breakpoint hit
522 uint64_t mask= ~(uint64_t(0)) // optional data or addr mask
523 );
524
525 // remove breakpoint bp_id
526 // if bp_id is ~(0) - remove all instruction bp
527 virtual int delete_breakpoint ( int bp_id = ~(0) );
528
529
530 // print breakpoint list to a file/consol
531 virtual int print_breakpoints ( FILE *fp );
532
533 // print all regs to file/consol
534 virtual int print_regs ( FILE *fp );
535
536 // print tlbs to file/consol
537 virtual int print_tlbs ( FILE *fp );
538
539 // Return cpu implementation name
540 static const char* cpu_name(VCPU_Type type)
541 {
542 switch (type & VCPU_IMPL_VER_MASK) {
543 case VCPU_IMPL_VER_SPITFIRE:
544 return "spitfire";
545 case VCPU_IMPL_VER_BLACKBIRD:
546 return "blackbird";
547 case VCPU_IMPL_VER_SABRE:
548 return "sabre";
549 case VCPU_IMPL_VER_SAPPHIRE:
550 return "sapphire";
551 case VCPU_IMPL_VER_CHEETAH:
552 return "ch";
553 case VCPU_IMPL_VER_CHPLUS:
554 return "chplus";
555 case VCPU_IMPL_VER_N1:
556 return "ni";
557 case VCPU_IMPL_VER_N2:
558 return "n2";
559 default:
560 return "unknown-cpu";
561 }
562 };
563};
564
565#endif // _CPU_LIB_INTERFACE_H