1 /* Interface definition for configurable Xtensa ISA support. 2 * 3 * Copyright (c) 2001-2013 Tensilica Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining 6 * a copy of this software and associated documentation files (the 7 * "Software"), to deal in the Software without restriction, including 8 * without limitation the rights to use, copy, modify, merge, publish, 9 * distribute, sublicense, and/or sell copies of the Software, and to 10 * permit persons to whom the Software is furnished to do so, subject to 11 * the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included 14 * in all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 */ 24 25 #ifndef XTENSA_LIBISA_H 26 #define XTENSA_LIBISA_H 27 28 #include <stdint.h> 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 /* 35 * Version number: This is intended to help support code that works with 36 * versions of this library from multiple Xtensa releases. 37 */ 38 39 #define XTENSA_ISA_VERSION 7000 40 41 /* 42 * This file defines the interface to the Xtensa ISA library. This 43 * library contains most of the ISA-specific information for a 44 * particular Xtensa processor. For example, the set of valid 45 * instructions, their opcode encodings and operand fields are all 46 * included here. 47 * 48 * This interface basically defines a number of abstract data types. 49 * 50 * . an instruction buffer - for holding the raw instruction bits 51 * . ISA info - information about the ISA as a whole 52 * . instruction formats - instruction size and slot structure 53 * . opcodes - information about individual instructions 54 * . operands - information about register and immediate instruction operands 55 * . stateOperands - information about processor state instruction operands 56 * . interfaceOperands - information about interface instruction operands 57 * . register files - register file information 58 * . processor states - internal processor state information 59 * . system registers - "special registers" and "user registers" 60 * . interfaces - TIE interfaces that are external to the processor 61 * . functional units - TIE shared functions 62 * 63 * The interface defines a set of functions to access each data type. 64 * With the exception of the instruction buffer, the internal 65 * representations of the data structures are hidden. All accesses must 66 * be made through the functions defined here. 67 */ 68 69 typedef struct xtensa_isa_opaque { int unused; } *xtensa_isa; 70 71 72 /* 73 * Most of the Xtensa ISA entities (e.g., opcodes, regfiles, etc.) are 74 * represented here using sequential integers beginning with 0. The 75 * specific values are only fixed for a particular instantiation of an 76 * xtensa_isa structure, so these values should only be used 77 * internally. 78 */ 79 80 typedef int xtensa_opcode; 81 typedef int xtensa_format; 82 typedef int xtensa_regfile; 83 typedef int xtensa_state; 84 typedef int xtensa_sysreg; 85 typedef int xtensa_interface; 86 typedef int xtensa_funcUnit; 87 88 89 /* Define a unique value for undefined items. */ 90 91 #define XTENSA_UNDEFINED -1 92 93 94 /* 95 * Overview of using this interface to decode/encode instructions: 96 * 97 * Each Xtensa instruction is associated with a particular instruction 98 * format, where the format defines a fixed number of slots for 99 * operations. The formats for the core Xtensa ISA have only one slot, 100 * but FLIX instructions may have multiple slots. Within each slot, 101 * there is a single opcode and some number of associated operands. 102 * 103 * The encoding and decoding functions operate on instruction buffers, 104 * not on the raw bytes of the instructions. The same instruction 105 * buffer data structure is used for both entire instructions and 106 * individual slots in those instructions -- the contents of a slot need 107 * to be extracted from or inserted into the buffer for the instruction 108 * as a whole. 109 * 110 * Decoding an instruction involves first finding the format, which 111 * identifies the number of slots, and then decoding each slot 112 * separately. A slot is decoded by finding the opcode and then using 113 * the opcode to determine how many operands there are. For example: 114 * 115 * xtensa_insnbuf_from_chars 116 * xtensa_format_decode 117 * for each slot { 118 * xtensa_format_get_slot 119 * xtensa_opcode_decode 120 * for each operand { 121 * xtensa_operand_get_field 122 * xtensa_operand_decode 123 * } 124 * } 125 * 126 * Encoding an instruction is roughly the same procedure in reverse: 127 * 128 * xtensa_format_encode 129 * for each slot { 130 * xtensa_opcode_encode 131 * for each operand { 132 * xtensa_operand_encode 133 * xtensa_operand_set_field 134 * } 135 * xtensa_format_set_slot 136 * } 137 * xtensa_insnbuf_to_chars 138 */ 139 140 141 /* Error handling. */ 142 143 /* 144 * Error codes. The code for the most recent error condition can be 145 * retrieved with the "errno" function. For any result other than 146 * xtensa_isa_ok, an error message containing additional information 147 * about the problem can be retrieved using the "error_msg" function. 148 * The error messages are stored in an internal buffer, which should 149 * not be freed and may be overwritten by subsequent operations. 150 */ 151 152 typedef enum xtensa_isa_status_enum { 153 xtensa_isa_ok = 0, 154 xtensa_isa_bad_format, 155 xtensa_isa_bad_slot, 156 xtensa_isa_bad_opcode, 157 xtensa_isa_bad_operand, 158 xtensa_isa_bad_field, 159 xtensa_isa_bad_iclass, 160 xtensa_isa_bad_regfile, 161 xtensa_isa_bad_sysreg, 162 xtensa_isa_bad_state, 163 xtensa_isa_bad_interface, 164 xtensa_isa_bad_funcUnit, 165 xtensa_isa_wrong_slot, 166 xtensa_isa_no_field, 167 xtensa_isa_out_of_memory, 168 xtensa_isa_buffer_overflow, 169 xtensa_isa_internal_error, 170 xtensa_isa_bad_value 171 } xtensa_isa_status; 172 173 xtensa_isa_status xtensa_isa_errno(xtensa_isa isa); 174 175 char *xtensa_isa_error_msg(xtensa_isa isa); 176 177 178 179 /* Instruction buffers. */ 180 181 typedef uint32_t xtensa_insnbuf_word; 182 typedef xtensa_insnbuf_word *xtensa_insnbuf; 183 184 185 /* Get the size in "insnbuf_words" of the xtensa_insnbuf array. */ 186 187 int xtensa_insnbuf_size(xtensa_isa isa); 188 189 190 /* Allocate an xtensa_insnbuf of the right size. */ 191 192 xtensa_insnbuf xtensa_insnbuf_alloc(xtensa_isa isa); 193 194 195 /* Release an xtensa_insnbuf. */ 196 197 void xtensa_insnbuf_free(xtensa_isa isa, xtensa_insnbuf buf); 198 199 200 /* 201 * Conversion between raw memory (char arrays) and our internal 202 * instruction representation. This is complicated by the Xtensa ISA's 203 * variable instruction lengths. When converting to chars, the buffer 204 * must contain a valid instruction so we know how many bytes to copy; 205 * thus, the "to_chars" function returns the number of bytes copied or 206 * XTENSA_UNDEFINED on error. The "from_chars" function first reads the 207 * minimal number of bytes required to decode the instruction length and 208 * then proceeds to copy the entire instruction into the buffer; if the 209 * memory does not contain a valid instruction, it copies the maximum 210 * number of bytes required for the longest Xtensa instruction. The 211 * "num_chars" argument may be used to limit the number of bytes that 212 * can be read or written. Otherwise, if "num_chars" is zero, the 213 * functions may read or write past the end of the code. 214 */ 215 216 int xtensa_insnbuf_to_chars(xtensa_isa isa, const xtensa_insnbuf insn, 217 unsigned char *cp, int num_chars); 218 219 void xtensa_insnbuf_from_chars(xtensa_isa isa, xtensa_insnbuf insn, 220 const unsigned char *cp, int num_chars); 221 222 223 224 /* ISA information. */ 225 226 /* Initialize the ISA information. */ 227 228 xtensa_isa xtensa_isa_init(void *xtensa_modules, xtensa_isa_status *errno_p, 229 char **error_msg_p); 230 231 232 /* Deallocate an xtensa_isa structure. */ 233 234 void xtensa_isa_free(xtensa_isa isa); 235 236 237 /* Get the maximum instruction size in bytes. */ 238 239 int xtensa_isa_maxlength(xtensa_isa isa); 240 241 242 /* 243 * Decode the length in bytes of an instruction in raw memory (not an 244 * insnbuf). This function reads only the minimal number of bytes 245 * required to decode the instruction length. Returns 246 * XTENSA_UNDEFINED on error. 247 */ 248 249 int xtensa_isa_length_from_chars(xtensa_isa isa, const unsigned char *cp); 250 251 252 /* 253 * Get the number of stages in the processor's pipeline. The pipeline 254 * stage values returned by other functions in this library will range 255 * from 0 to N-1, where N is the value returned by this function. 256 * Note that the stage numbers used here may not correspond to the 257 * actual processor hardware, e.g., the hardware may have additional 258 * stages before stage 0. Returns XTENSA_UNDEFINED on error. 259 */ 260 261 int xtensa_isa_num_pipe_stages(xtensa_isa isa); 262 263 264 /* Get the number of various entities that are defined for this processor. */ 265 266 int xtensa_isa_num_formats(xtensa_isa isa); 267 268 int xtensa_isa_num_opcodes(xtensa_isa isa); 269 270 int xtensa_isa_num_regfiles(xtensa_isa isa); 271 272 int xtensa_isa_num_states(xtensa_isa isa); 273 274 int xtensa_isa_num_sysregs(xtensa_isa isa); 275 276 int xtensa_isa_num_interfaces(xtensa_isa isa); 277 278 int xtensa_isa_num_funcUnits(xtensa_isa isa); 279 280 281 282 /* Instruction formats. */ 283 284 /* Get the name of a format. Returns null on error. */ 285 286 const char *xtensa_format_name(xtensa_isa isa, xtensa_format fmt); 287 288 289 /* 290 * Given a format name, return the format number. Returns 291 * XTENSA_UNDEFINED if the name is not a valid format. 292 */ 293 294 xtensa_format xtensa_format_lookup(xtensa_isa isa, const char *fmtname); 295 296 297 /* 298 * Decode the instruction format from a binary instruction buffer. 299 * Returns XTENSA_UNDEFINED if the format is not recognized. 300 */ 301 302 xtensa_format xtensa_format_decode(xtensa_isa isa, const xtensa_insnbuf insn); 303 304 305 /* 306 * Set the instruction format field(s) in a binary instruction buffer. 307 * All the other fields are set to zero. Returns non-zero on error. 308 */ 309 310 int xtensa_format_encode(xtensa_isa isa, xtensa_format fmt, 311 xtensa_insnbuf insn); 312 313 314 /* 315 * Find the length (in bytes) of an instruction. Returns 316 * XTENSA_UNDEFINED on error. 317 */ 318 319 int xtensa_format_length(xtensa_isa isa, xtensa_format fmt); 320 321 322 /* 323 * Get the number of slots in an instruction. Returns XTENSA_UNDEFINED 324 * on error. 325 */ 326 327 int xtensa_format_num_slots(xtensa_isa isa, xtensa_format fmt); 328 329 330 /* 331 * Get the opcode for a no-op in a particular slot. 332 * Returns XTENSA_UNDEFINED on error. 333 */ 334 335 xtensa_opcode xtensa_format_slot_nop_opcode(xtensa_isa isa, xtensa_format fmt, 336 int slot); 337 338 339 /* 340 * Get the bits for a specified slot out of an insnbuf for the 341 * instruction as a whole and put them into an insnbuf for that one 342 * slot, and do the opposite to set a slot. Return non-zero on error. 343 */ 344 345 int xtensa_format_get_slot(xtensa_isa isa, xtensa_format fmt, int slot, 346 const xtensa_insnbuf insn, xtensa_insnbuf slotbuf); 347 348 int xtensa_format_set_slot(xtensa_isa isa, xtensa_format fmt, int slot, 349 xtensa_insnbuf insn, const xtensa_insnbuf slotbuf); 350 351 352 353 /* Opcode information. */ 354 355 /* 356 * Translate a mnemonic name to an opcode. Returns XTENSA_UNDEFINED if 357 * the name is not a valid opcode mnemonic. 358 */ 359 360 xtensa_opcode xtensa_opcode_lookup(xtensa_isa isa, const char *opname); 361 362 363 /* 364 * Decode the opcode for one instruction slot from a binary instruction 365 * buffer. Returns the opcode or XTENSA_UNDEFINED if the opcode is 366 * illegal. 367 */ 368 369 xtensa_opcode xtensa_opcode_decode(xtensa_isa isa, xtensa_format fmt, int slot, 370 const xtensa_insnbuf slotbuf); 371 372 373 /* 374 * Set the opcode field(s) for an instruction slot. All other fields 375 * in the slot are set to zero. Returns non-zero if the opcode cannot 376 * be encoded. 377 */ 378 379 int xtensa_opcode_encode(xtensa_isa isa, xtensa_format fmt, int slot, 380 xtensa_insnbuf slotbuf, xtensa_opcode opc); 381 382 383 /* Get the mnemonic name for an opcode. Returns null on error. */ 384 385 const char *xtensa_opcode_name(xtensa_isa isa, xtensa_opcode opc); 386 387 388 /* Check various properties of opcodes. These functions return 0 if 389 * the condition is false, 1 if the condition is true, and 390 * XTENSA_UNDEFINED on error. The instructions are classified as 391 * follows: 392 * 393 * branch: conditional branch; may fall through to next instruction (B*) 394 * jump: unconditional branch (J, JX, RET*, RF*) 395 * loop: zero-overhead loop (LOOP*) 396 * call: unconditional call; control returns to next instruction (CALL*) 397 * 398 * For the opcodes that affect control flow in some way, the branch 399 * target may be specified by an immediate operand or it may be an 400 * address stored in a register. You can distinguish these by 401 * checking if the instruction has a PC-relative immediate 402 * operand. 403 */ 404 405 int xtensa_opcode_is_branch(xtensa_isa isa, xtensa_opcode opc); 406 407 int xtensa_opcode_is_jump(xtensa_isa isa, xtensa_opcode opc); 408 409 int xtensa_opcode_is_loop(xtensa_isa isa, xtensa_opcode opc); 410 411 int xtensa_opcode_is_call(xtensa_isa isa, xtensa_opcode opc); 412 413 414 /* 415 * Find the number of ordinary operands, state operands, and interface 416 * operands for an instruction. These return XTENSA_UNDEFINED on 417 * error. 418 */ 419 420 int xtensa_opcode_num_operands(xtensa_isa isa, xtensa_opcode opc); 421 422 int xtensa_opcode_num_stateOperands(xtensa_isa isa, xtensa_opcode opc); 423 424 int xtensa_opcode_num_interfaceOperands(xtensa_isa isa, xtensa_opcode opc); 425 426 427 /* 428 * Get functional unit usage requirements for an opcode. Each "use" 429 * is identified by a <functional unit, pipeline stage> pair. The 430 * "num_funcUnit_uses" function returns the number of these "uses" or 431 * XTENSA_UNDEFINED on error. The "funcUnit_use" function returns 432 * a pointer to a "use" pair or null on error. 433 */ 434 435 typedef struct xtensa_funcUnit_use_struct { 436 xtensa_funcUnit unit; 437 int stage; 438 } xtensa_funcUnit_use; 439 440 int xtensa_opcode_num_funcUnit_uses(xtensa_isa isa, xtensa_opcode opc); 441 442 xtensa_funcUnit_use *xtensa_opcode_funcUnit_use(xtensa_isa isa, 443 xtensa_opcode opc, int u); 444 445 446 447 /* Operand information. */ 448 449 /* Get the name of an operand. Returns null on error. */ 450 451 const char *xtensa_operand_name(xtensa_isa isa, xtensa_opcode opc, int opnd); 452 453 454 /* 455 * Some operands are "invisible", i.e., not explicitly specified in 456 * assembly language. When assembling an instruction, you need not set 457 * the values of invisible operands, since they are either hardwired or 458 * derived from other field values. The values of invisible operands 459 * can be examined in the same way as other operands, but remember that 460 * an invisible operand may get its value from another visible one, so 461 * the entire instruction must be available before examining the 462 * invisible operand values. This function returns 1 if an operand is 463 * visible, 0 if it is invisible, or XTENSA_UNDEFINED on error. Note 464 * that whether an operand is visible is orthogonal to whether it is 465 * "implicit", i.e., whether it is encoded in a field in the 466 * instruction. 467 */ 468 469 int xtensa_operand_is_visible(xtensa_isa isa, xtensa_opcode opc, int opnd); 470 471 472 /* 473 * Check if an operand is an input ('i'), output ('o'), or inout ('m') 474 * operand. Note: The output operand of a conditional assignment 475 * (e.g., movnez) appears here as an inout ('m') even if it is declared 476 * in the TIE code as an output ('o'); this allows the compiler to 477 * properly handle register allocation for conditional assignments. 478 * Returns 0 on error. 479 */ 480 481 char xtensa_operand_inout(xtensa_isa isa, xtensa_opcode opc, int opnd); 482 483 484 /* 485 * Get and set the raw (encoded) value of the field for the specified 486 * operand. The "set" function does not check if the value fits in the 487 * field; that is done by the "encode" function below. Both of these 488 * functions return non-zero on error, e.g., if the field is not defined 489 * for the specified slot. 490 */ 491 492 int xtensa_operand_get_field(xtensa_isa isa, xtensa_opcode opc, int opnd, 493 xtensa_format fmt, int slot, 494 const xtensa_insnbuf slotbuf, uint32_t *valp); 495 496 int xtensa_operand_set_field(xtensa_isa isa, xtensa_opcode opc, int opnd, 497 xtensa_format fmt, int slot, 498 xtensa_insnbuf slotbuf, uint32_t val); 499 500 501 /* 502 * Encode and decode operands. The raw bits in the operand field may 503 * be encoded in a variety of different ways. These functions hide 504 * the details of that encoding. The result values are returned through 505 * the argument pointer. The return value is non-zero on error. 506 */ 507 508 int xtensa_operand_encode(xtensa_isa isa, xtensa_opcode opc, int opnd, 509 uint32_t *valp); 510 511 int xtensa_operand_decode(xtensa_isa isa, xtensa_opcode opc, int opnd, 512 uint32_t *valp); 513 514 515 /* 516 * An operand may be either a register operand or an immediate of some 517 * sort (e.g., PC-relative or not). The "is_register" function returns 518 * 0 if the operand is an immediate, 1 if it is a register, and 519 * XTENSA_UNDEFINED on error. The "regfile" function returns the 520 * regfile for a register operand, or XTENSA_UNDEFINED on error. 521 */ 522 523 int xtensa_operand_is_register(xtensa_isa isa, xtensa_opcode opc, int opnd); 524 525 xtensa_regfile xtensa_operand_regfile(xtensa_isa isa, xtensa_opcode opc, 526 int opnd); 527 528 529 /* 530 * Register operands may span multiple consecutive registers, e.g., a 531 * 64-bit data type may occupy two 32-bit registers. Only the first 532 * register is encoded in the operand field. This function specifies 533 * the number of consecutive registers occupied by this operand. For 534 * non-register operands, the return value is undefined. Returns 535 * XTENSA_UNDEFINED on error. 536 */ 537 538 int xtensa_operand_num_regs(xtensa_isa isa, xtensa_opcode opc, int opnd); 539 540 541 /* 542 * Some register operands do not completely identify the register being 543 * accessed. For example, the operand value may be added to an internal 544 * state value. By definition, this implies that the corresponding 545 * regfile is not allocatable. Unknown registers should generally be 546 * treated with worst-case assumptions. The function returns 0 if the 547 * register value is unknown, 1 if known, and XTENSA_UNDEFINED on 548 * error. 549 */ 550 551 int xtensa_operand_is_known_reg(xtensa_isa isa, xtensa_opcode opc, int opnd); 552 553 554 /* 555 * Check if an immediate operand is PC-relative. Returns 0 for register 556 * operands and non-PC-relative immediates, 1 for PC-relative 557 * immediates, and XTENSA_UNDEFINED on error. 558 */ 559 560 int xtensa_operand_is_PCrelative(xtensa_isa isa, xtensa_opcode opc, int opnd); 561 562 563 /* 564 * For PC-relative offset operands, the interpretation of the offset may 565 * vary between opcodes, e.g., is it relative to the current PC or that 566 * of the next instruction? The following functions are defined to 567 * perform PC-relative relocations and to undo them (as in the 568 * disassembler). The "do_reloc" function takes the desired address 569 * value and the PC of the current instruction and sets the value to the 570 * corresponding PC-relative offset (which can then be encoded and 571 * stored into the operand field). The "undo_reloc" function takes the 572 * unencoded offset value and the current PC and sets the value to the 573 * appropriate address. The return values are non-zero on error. Note 574 * that these functions do not replace the encode/decode functions; the 575 * operands must be encoded/decoded separately and the encode functions 576 * are responsible for detecting invalid operand values. 577 */ 578 579 int xtensa_operand_do_reloc(xtensa_isa isa, xtensa_opcode opc, int opnd, 580 uint32_t *valp, uint32_t pc); 581 582 int xtensa_operand_undo_reloc(xtensa_isa isa, xtensa_opcode opc, int opnd, 583 uint32_t *valp, uint32_t pc); 584 585 586 587 /* State Operands. */ 588 589 /* 590 * Get the state accessed by a state operand. Returns XTENSA_UNDEFINED 591 * on error. 592 */ 593 594 xtensa_state xtensa_stateOperand_state(xtensa_isa isa, xtensa_opcode opc, 595 int stOp); 596 597 598 /* 599 * Check if a state operand is an input ('i'), output ('o'), or inout 600 * ('m') operand. Returns 0 on error. 601 */ 602 603 char xtensa_stateOperand_inout(xtensa_isa isa, xtensa_opcode opc, int stOp); 604 605 606 607 /* Interface Operands. */ 608 609 /* 610 * Get the external interface accessed by an interface operand. 611 * Returns XTENSA_UNDEFINED on error. 612 */ 613 614 xtensa_interface xtensa_interfaceOperand_interface(xtensa_isa isa, 615 xtensa_opcode opc, 616 int ifOp); 617 618 619 620 /* Register Files. */ 621 622 /* 623 * Regfiles include both "real" regfiles and "views", where a view 624 * allows a group of adjacent registers in a real "parent" regfile to be 625 * viewed as a single register. A regfile view has all the same 626 * properties as its parent except for its (long) name, bit width, number 627 * of entries, and default ctype. You can use the parent function to 628 * distinguish these two classes. 629 */ 630 631 /* 632 * Look up a regfile by either its name or its abbreviated "short name". 633 * Returns XTENSA_UNDEFINED on error. The "lookup_shortname" function 634 * ignores "view" regfiles since they always have the same shortname as 635 * their parents. 636 */ 637 638 xtensa_regfile xtensa_regfile_lookup(xtensa_isa isa, const char *name); 639 640 xtensa_regfile xtensa_regfile_lookup_shortname(xtensa_isa isa, 641 const char *shortname); 642 643 644 /* 645 * Get the name or abbreviated "short name" of a regfile. 646 * Returns null on error. 647 */ 648 649 const char *xtensa_regfile_name(xtensa_isa isa, xtensa_regfile rf); 650 651 const char *xtensa_regfile_shortname(xtensa_isa isa, xtensa_regfile rf); 652 653 654 /* 655 * Get the parent regfile of a "view" regfile. If the regfile is not a 656 * view, the result is the same as the input parameter. Returns 657 * XTENSA_UNDEFINED on error. 658 */ 659 660 xtensa_regfile xtensa_regfile_view_parent(xtensa_isa isa, xtensa_regfile rf); 661 662 663 /* 664 * Get the bit width of a regfile or regfile view. 665 * Returns XTENSA_UNDEFINED on error. 666 */ 667 668 int xtensa_regfile_num_bits(xtensa_isa isa, xtensa_regfile rf); 669 670 671 /* 672 * Get the number of regfile entries. Returns XTENSA_UNDEFINED on 673 * error. 674 */ 675 676 int xtensa_regfile_num_entries(xtensa_isa isa, xtensa_regfile rf); 677 678 679 680 /* Processor States. */ 681 682 /* Look up a state by name. Returns XTENSA_UNDEFINED on error. */ 683 684 xtensa_state xtensa_state_lookup(xtensa_isa isa, const char *name); 685 686 687 /* Get the name for a processor state. Returns null on error. */ 688 689 const char *xtensa_state_name(xtensa_isa isa, xtensa_state st); 690 691 692 /* 693 * Get the bit width for a processor state. 694 * Returns XTENSA_UNDEFINED on error. 695 */ 696 697 int xtensa_state_num_bits(xtensa_isa isa, xtensa_state st); 698 699 700 /* 701 * Check if a state is exported from the processor core. Returns 0 if 702 * the condition is false, 1 if the condition is true, and 703 * XTENSA_UNDEFINED on error. 704 */ 705 706 int xtensa_state_is_exported(xtensa_isa isa, xtensa_state st); 707 708 709 /* 710 * Check for a "shared_or" state. Returns 0 if the condition is false, 711 * 1 if the condition is true, and XTENSA_UNDEFINED on error. 712 */ 713 714 int xtensa_state_is_shared_or(xtensa_isa isa, xtensa_state st); 715 716 717 718 /* Sysregs ("special registers" and "user registers"). */ 719 720 /* 721 * Look up a register by its number and whether it is a "user register" 722 * or a "special register". Returns XTENSA_UNDEFINED if the sysreg does 723 * not exist. 724 */ 725 726 xtensa_sysreg xtensa_sysreg_lookup(xtensa_isa isa, int num, int is_user); 727 728 729 /* 730 * Check if there exists a sysreg with a given name. 731 * If not, this function returns XTENSA_UNDEFINED. 732 */ 733 734 xtensa_sysreg xtensa_sysreg_lookup_name(xtensa_isa isa, const char *name); 735 736 737 /* Get the name of a sysreg. Returns null on error. */ 738 739 const char *xtensa_sysreg_name(xtensa_isa isa, xtensa_sysreg sysreg); 740 741 742 /* Get the register number. Returns XTENSA_UNDEFINED on error. */ 743 744 int xtensa_sysreg_number(xtensa_isa isa, xtensa_sysreg sysreg); 745 746 747 /* 748 * Check if a sysreg is a "special register" or a "user register". 749 * Returns 0 for special registers, 1 for user registers and 750 * XTENSA_UNDEFINED on error. 751 */ 752 753 int xtensa_sysreg_is_user(xtensa_isa isa, xtensa_sysreg sysreg); 754 755 756 757 /* Interfaces. */ 758 759 /* 760 * Find an interface by name. The return value is XTENSA_UNDEFINED if 761 * the specified interface is not found. 762 */ 763 764 xtensa_interface xtensa_interface_lookup(xtensa_isa isa, const char *ifname); 765 766 767 /* Get the name of an interface. Returns null on error. */ 768 769 const char *xtensa_interface_name(xtensa_isa isa, xtensa_interface intf); 770 771 772 /* 773 * Get the bit width for an interface. 774 * Returns XTENSA_UNDEFINED on error. 775 */ 776 777 int xtensa_interface_num_bits(xtensa_isa isa, xtensa_interface intf); 778 779 780 /* 781 * Check if an interface is an input ('i') or output ('o') with respect 782 * to the Xtensa processor core. Returns 0 on error. 783 */ 784 785 char xtensa_interface_inout(xtensa_isa isa, xtensa_interface intf); 786 787 788 /* 789 * Check if accessing an interface has potential side effects. 790 * Currently "data" interfaces have side effects and "control" 791 * interfaces do not. Returns 1 if there are side effects, 0 if not, 792 * and XTENSA_UNDEFINED on error. 793 */ 794 795 int xtensa_interface_has_side_effect(xtensa_isa isa, xtensa_interface intf); 796 797 798 /* 799 * Some interfaces may be related such that accessing one interface 800 * has side effects on a set of related interfaces. The interfaces 801 * are partitioned into equivalence classes of related interfaces, and 802 * each class is assigned a unique identifier number. This function 803 * returns the class identifier for an interface, or XTENSA_UNDEFINED 804 * on error. These identifiers can be compared to determine if two 805 * interfaces are related; the specific values of the identifiers have 806 * no particular meaning otherwise. 807 */ 808 809 int xtensa_interface_class_id(xtensa_isa isa, xtensa_interface intf); 810 811 812 /* Functional Units. */ 813 814 /* 815 * Find a functional unit by name. The return value is XTENSA_UNDEFINED if 816 * the specified unit is not found. 817 */ 818 819 xtensa_funcUnit xtensa_funcUnit_lookup(xtensa_isa isa, const char *fname); 820 821 822 /* Get the name of a functional unit. Returns null on error. */ 823 824 const char *xtensa_funcUnit_name(xtensa_isa isa, xtensa_funcUnit fun); 825 826 827 /* 828 * Functional units may be replicated. See how many instances of a 829 * particular function unit exist. Returns XTENSA_UNDEFINED on error. 830 */ 831 832 int xtensa_funcUnit_num_copies(xtensa_isa isa, xtensa_funcUnit fun); 833 834 835 #ifdef __cplusplus 836 } 837 #endif 838 #endif /* XTENSA_LIBISA_H */ 839