Project

General

Profile

Actions

Task #5350

closed

Labels in the text of instruction calls

Added by Andrei Tatarnikov over 9 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
High
Assignee:
Andrei Tatarnikov
Category:
ISA Simulator
Target version:
Start date:
10/16/2014
Due date:
% Done:

100%

Estimated time:
Detected in build:
svn
Published in build:

Description

Не обходим вменяемый механизм использования меток в сгенерированом коде инструкций. Сейчас используется ненадёжно решение, основанное на замене текста (r2689).

Суть проблемы состоит в следующем. Вот типичный код операции ветвления:

op BEQ (rs : R, rt : R, offset : SHORT)
  syntax = format("BEQ %s, %s, %<label>d", rs.syntax, rt.syntax, offset)
  image  = format("000100%s%s%s", rs.image, rt.image, offset)
  action = {
    if rs == rt then
      // Informs that control transfer is to be performed
      BRANCH = 1;
      // Calculates the jump address and saves it to a temporary variable
      JMPADDR = NIA + (offset << 3);
    endif;
  }

Адрес для перехода получается на основе параметра offset (смещение), который представляет собой некоторую числовую константу. В тестовом шаблоне этот параметр может задаваться как обращение к некой метке и при этом инструкции будет передана некая произвольная (fake) константа, т.к. у нас сейчас нет модели памяти и мы не можем вычислить смещение. Проблема: при герации кода у нас получается некорректный код: вызов инструкции B будет с произвольным смещением. Поэтому, необходимо в таких случах вместо fake аргумента подставлять имя метки. При этом важно поддерживать оба варианта использования: (1) передавать инструкции константные значения и (2) использовать метки.

Нужно продумать решение. Скорее всего поддержка должна быть на уровне модели. Т.е. модель должна уметь регистрировать метки и подставлять соответствующие имена, если метка для данного значения зарегистрирована.

В Sim-nML добавлено следующее соглашение. В строке форматирования используется тег <label> для обозначения значений, которые могут быть заменены на имя соответствующей метки.

syntax = format("BEQ %s, %s, %<label>d", rs.syntax, rt.syntax, offset)
Actions #1

Updated by Alexander Kamkin over 9 years ago

  • Target version set to 2.1
Actions #2

Updated by Alexander Kamkin about 9 years ago

  • Subject changed from [model] Labels in the text of instruction calls to Labels in the text of instruction calls
  • Category set to ISA Simulator
Actions #3

Updated by Alexander Kamkin almost 9 years ago

  • Target version changed from 2.1 to 2.2
Actions #4

Updated by Andrei Tatarnikov about 6 years ago

  • Status changed from New to Resolved
  • % Done changed from 0 to 100

The problem has been solving for establishing a special addressing mode responsible for label handling. Here is an example:


// This mode calculates offset on the basis of the target label address and the current instruction address.
label mode BRANCH_LABEL(target: WORD, current: WORD) = target<17..2> - current<17..2> - 1
  syntax = "" // This will be replaced by the label name.
  image = format("%s", target<17..2> - current<17..2> - 1)

// The immediate offset.
mode BRANCH_IMM(imm: SHORT) = imm
  syntax = format("0x%X", imm)
  image = format("%s", imm)

mode BRANCH_OFFSET = BRANCH_LABEL | BRANCH_IMM

op beq (rs: REG, rt: REG, offset: BRANCH_OFFSET)
  syntax = format("beq %s, %s, %s", rs.syntax, rt.syntax, offset.syntax)
  image = format("000100%s%s%s", rs.image, rt.image, offset.image)
  action = {
    if rs == rt then
      BRANCH = 1;
      JMPADDR = CIA + 4 + (sign_extend(WORD, offset) << 2);
    endif;
  }
Actions #5

Updated by Alexander Kamkin over 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF