JPH06324883A - Cpu simulator - Google Patents

Cpu simulator

Info

Publication number
JPH06324883A
JPH06324883A JP13659793A JP13659793A JPH06324883A JP H06324883 A JPH06324883 A JP H06324883A JP 13659793 A JP13659793 A JP 13659793A JP 13659793 A JP13659793 A JP 13659793A JP H06324883 A JPH06324883 A JP H06324883A
Authority
JP
Japan
Prior art keywords
instruction
cpu
instruction code
address
simulation
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
JP13659793A
Other languages
Japanese (ja)
Other versions
JP2788839B2 (en
Inventor
Naoki Sato
直樹 佐藤
Soichi Otsuka
壮一 大塚
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NIPPON DENKI GIJUTSU JOHO SYST
NIPPON DENKI GIJUTSU JOHO SYST KAIHATSU KK
NEC Corp
Original Assignee
NIPPON DENKI GIJUTSU JOHO SYST
NIPPON DENKI GIJUTSU JOHO SYST KAIHATSU KK
NEC Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by NIPPON DENKI GIJUTSU JOHO SYST, NIPPON DENKI GIJUTSU JOHO SYST KAIHATSU KK, NEC Corp filed Critical NIPPON DENKI GIJUTSU JOHO SYST
Priority to JP5136597A priority Critical patent/JP2788839B2/en
Publication of JPH06324883A publication Critical patent/JPH06324883A/en
Application granted granted Critical
Publication of JP2788839B2 publication Critical patent/JP2788839B2/en
Anticipated expiration legal-status Critical
Expired - Fee Related legal-status Critical Current

Links

Landscapes

  • Test And Diagnosis Of Digital Computers (AREA)

Abstract

PURPOSE:To convert an instruction code into the instruction sequence of a host CPU for simulation correctly without being affected by the mixture of data unused as the instruction code in an address area referred as the instruction code by a target CPU even when it occurs and to simulate the operation of the target CPU on the host CPU without generating a trouble. CONSTITUTION:At a pre-stage to simulate the operation of the target CPU on the host CPU, a conversion means 2 interprets binary data 1 in an address area referred as the instruction code by the target CPU as the instruction code setting all the addresses 0, 1, 2,... as bases where the instruction code can be arranged, and converts an interpreted instruction code into simulation instruction sequences 3-1, 3-2, 3-3,... comprised of the instruction sequence of the host CPU which simulates the instruction code and the instruction sequence which transfers control to the instruction sequence of the host CPU which performs the simulation of the instruction code executed by the target CPU following the interpreted instruction code.

Description

【発明の詳細な説明】Detailed Description of the Invention

【0001】[0001]

【産業上の利用分野】本発明は、ターゲットCPUの動
作をホストCPU上でシミュレートする技術に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a technique for simulating the operation of a target CPU on a host CPU.

【0002】[0002]

【従来の技術】ターゲットCPUを含むターゲットマシ
ンの完成前に、或いはターゲットマシン上でのデバッ
グ,性能評価前に、ターゲットCPU用に開発されたプ
ログラム(ターゲットプログラムと称す)をデバッグし
たり、性能評価を行う方法として、ターゲットCPUと
は別のCPUであるホストCPUを含むCPUシミュレ
ータ上でターゲットプログラムにかかるターゲットCP
Uの動作をシミュレートする方法があり、その方法は、
ターゲットCPU用のソースプログラムを逐次解釈実行
するインタプリタ方式と、ターゲットCPU用のマシン
語コードを逐次解釈実行するオブジェクトシミュレーシ
ョン方式とに大別される(例えば、社団法人電子情報通
信学会ハンドブック委員会編集,株式会社オーム社昭和
63年3月30日発行,第1版「電子情報通信ハンドブ
ック第2分冊」1857頁,5・3「シミュレータ」参
照)。
2. Description of the Related Art A program developed for a target CPU (referred to as a target program) can be debugged or performance evaluated before completion of a target machine including a target CPU or before debugging and performance evaluation on the target machine. As a method of executing the target CPU, the target CP for the target program on the CPU simulator including the host CPU which is a CPU different from the target CPU
There is a method to simulate the behavior of U.
It is roughly divided into an interpreter method that sequentially interprets and executes the source program for the target CPU and an object simulation method that sequentially interprets and executes the machine language code for the target CPU (for example, edited by the Institute of Electronics, Information and Communication Engineers Handbook Committee, Ohmsha Co., Ltd., issued March 30, 1988, first edition "Electronic Information and Communication Handbook Second Volume", page 1857, 5.3 "Simulator").

【0003】ここで、インタプリタ方式は、ターゲット
CPU用の原始プログラム(ソースプログラム)を直接
にインタプリートしつつシミュレートするものであり、
オブジェクトシミュレーション方式は、シミュレートに
先立ってターゲットプログラムの原始プログラム(ソー
スプログラム)をコンパイルまたはアセンブルしてター
ゲットCPUのマシン語レベルの命令コードに変換し、
この命令コードをシミュレートするものである。
Here, the interpreter method is a method for simulating a source program for a target CPU while directly interpreting it.
The object simulation method compiles or assembles a source program of a target program prior to simulation to convert it into a machine language level instruction code of the target CPU,
This instruction code is simulated.

【0004】オブジェクトシミュレーション方式は、タ
ーゲットCPUのマシン語レベルの命令生成のための時
間がかかるが、シミュレートの実行時間はインタプリタ
方式に比べて速くなるため、短いシミュレート時間を要
求される場合にはオブジェクトシミュレーション方式が
用いられる。なお、ターゲットプログラムがマシン語レ
ベルで既に存在する場合には、コンパイルまたはアセン
ブルが不要であることは勿論のことである。
The object simulation method takes time to generate machine language level instructions of the target CPU, but the simulation execution time is faster than that of the interpreter method, so that a short simulation time is required. Uses an object simulation method. Needless to say, if the target program already exists at the machine language level, no compilation or assembly is necessary.

【0005】そして、オブジェクトシミュレーション方
式のCPUシミュレータにおいては、例えば特開平2−
250122号公報に見られるように、ターゲットCP
Uの命令コードをホストCPU上で実行時に1命令ずつ
解釈しながらシミュレートを進めていた。
In an object simulation type CPU simulator, for example, Japanese Unexamined Patent Publication No.
As disclosed in Japanese Patent No. 250122, the target CP
The U instruction code was interpreted on the host CPU one by one at the time of execution, and the simulation was advanced.

【0006】このようにオブジェクトシミュレーション
方式のCPUシミュレータはインタプリタ方式のものに
比べてシミュレーション速度の点で優れているが、従来
のようにターゲットCPUの命令コードをホストCPU
上で実行時に1命令ずつ解釈する構成では、その解釈の
ために要する時間がシミュレーション時のオーバヘッド
となる。
As described above, the object simulator type CPU simulator is superior to the interpreter type CPU in simulation speed. However, as in the conventional case, the instruction code of the target CPU is changed to the host CPU.
In the above configuration in which each instruction is interpreted at the time of execution, the time required for the interpretation becomes an overhead at the time of simulation.

【0007】そこで本発明者の一人は、シミュレーショ
ン実行時におけるターゲットCPUの命令コードの解釈
を不要にすることにより高速なシミュレーションを可能
とした新規なCPUシミュレータ(以下、既提案CPU
シミュレータと称す)を、平成4年12月29日提出の
特許願(整理番号N0002S,発明の名称;CPUシ
ミュレーション方法およびCPUシミュレータ)、およ
び平成5年2月26日提出の特許願(整理番号N000
4S,発明の名称;CPUシミュレーション方法および
CPUシミュレータ)において提案した。
Therefore, one of the inventors of the present invention is a novel CPU simulator (hereinafter referred to as a previously proposed CPU) that enables high-speed simulation by eliminating the need to interpret the instruction code of the target CPU when executing the simulation.
Patent application filed on December 29, 1992 (reference number N0002S, title of invention; CPU simulation method and CPU simulator), and patent application filed on February 26, 1993 (reference number N000).
4S, title of invention; CPU simulation method and CPU simulator).

【0008】この既提案CPUシミュレータは、ターゲ
ットCPUの動作をホストCPU上でシミュレートする
CPUシミュレータにおいて、ターゲットプログラムの
マシン語レベルの命令コードを事前にまとめて解釈し、
各命令コードをシミュレートするホストCPUのアセン
ブラ言語レベル或いはマシン語レベルの命令コードの組
み合わせ、または各命令コードをシミュレートするホス
トCPUで実行可能なシミュレーション関数を呼び出す
シミュレーション関数呼び出しの集合で表現されたシミ
ュレーションプログラムを生成し、この生成したシミュ
レーションプログラムをホストCPUで実行するもので
あり、シミュレーション実行時におけるターゲットCP
Uの命令コードの解釈が不要になる為、その分、高速な
シミュレーションが可能になる。
In this already proposed CPU simulator, in a CPU simulator that simulates the operation of the target CPU on the host CPU, machine code level instruction codes of the target program are collectively interpreted in advance,
It is expressed by a combination of assembler language level or machine language level instruction codes of the host CPU that simulates each instruction code, or a set of simulation function calls that call a simulation function that can be executed by the host CPU that simulates each instruction code. A simulation program is generated, and the generated simulation program is executed by the host CPU. The target CP at the time of executing the simulation.
Since it is not necessary to interpret the U instruction code, high-speed simulation is possible accordingly.

【0009】[0009]

【発明が解決しようとする課題】ところで、ターゲット
CPUが命令コードとして参照するターゲットプログラ
ム上のアドレス領域を図5(a)の符号Mに示すように
例えば番地0から始まる領域(1つの番地の記憶サイズ
は1バイトとする)であるとすると、ターゲットCPU
の命令コードのシミュレーションのためのホストCPU
の命令列への変換は次のように行うのが一般的である。
By the way, the address area on the target program referred to by the target CPU as an instruction code is, for example, an area starting from address 0 as shown by reference character M (storage of one address). If the size is 1 byte), the target CPU
Host CPU for simulation of instruction code
Is generally converted as follows.

【0010】先ず、番地0を基点とし、番地0に格納さ
れているバイナリデータのみでターゲットCPUの1バ
イトの命令コードを構成するか否かを調べ、構成してい
ればその命令コードをホストCPUの命令列に変換し、
番地1を次の基点とする。番地0に格納されているバイ
ナリデータのみでは1つの命令コードを構成しない場
合、次の番地1に格納されているバイナリデータを含め
た2バイトで同様の判別を行い、この2バイトのバイナ
リデータでターゲットCPUの2バイトの命令コードを
構成していれば、その命令コードをホストCPUの命令
列に変換し、番地3を次の基点とする。以下、同様に、
アドレス領域MのバイナリデータをターゲットCPUの
命令コードが出現する順番に順次解釈して変換してい
く。
First, it is checked whether or not the 1-byte instruction code of the target CPU is constituted only by the binary data stored in the address 0 with the address 0 as a starting point. Converted to the instruction sequence of
Address 1 is the next base point. If one binary code stored at address 0 does not constitute one instruction code, the same determination is made with 2 bytes including the binary data stored at the next address 1, and the binary data of this 2 bytes is used. If the 2-byte instruction code of the target CPU is configured, the instruction code is converted into the instruction string of the host CPU, and the address 3 is set as the next base point. Hereafter, similarly,
The binary data in the address area M is sequentially interpreted and converted in the order in which the instruction code of the target CPU appears.

【0011】以上のような方法によると、図5(a)に
示すように、アドレス領域MにターゲットCPUの命令
コードのみが格納されている場合には、同図のターゲッ
トCPUの命令コード(1),命令コード(2),命令
コード(3)を正しくホストCPUの命令列に変換する
ことはできるが、図5(b)に示すように、アドレス領
域M中の例えば番地2にターゲットCPUが命令コード
として使用しないバイナリデータXが混在している場
合、番地2を基点とする処理において番地2と例えば次
の番地3とに格納されたバイナリデータで若しターゲッ
トCPUの2バイトの或る命令コードが構成されたとす
ると、次の基点が番地4になるため、これ以降に解釈す
る命令コードの位置がずれてシミュレーション対象とな
る命令コードが変換されず、ホストCPU上でシミュレ
ーションできないことになる。
According to the above method, when only the instruction code of the target CPU is stored in the address area M as shown in FIG. 5A, the instruction code (1 ), The instruction code (2), and the instruction code (3) can be correctly converted into the instruction sequence of the host CPU, but as shown in FIG. 5B, the target CPU is, for example, address 2 in the address area M. When the binary data X that is not used as an instruction code is mixed, the binary data stored in the address 2 and, for example, the next address 3 in the processing starting from the address 2 is a certain 2-byte instruction of the target CPU. If the code is constructed, the next base point will be the address 4, so the position of the instruction code to be interpreted after that will shift and the instruction code to be simulated will be converted. It is not, and can not be simulated on the host CPU.

【0012】本発明はこのような問題点を解決するもの
であり、その目的は、ターゲットCPUが命令コードと
して参照するアドレス領域中にターゲットCPUが命令
コードとして使わないバイナリデータが混在している場
合であっても、それに影響されずに、アドレス領域中に
存在するターゲットCPUの各命令コードをホストCP
Uの命令列に正しく変換できるようにして、ターゲット
CPUの動作をホストCPU上で支障なくシミュレーシ
ョンできるようにすることにある。
The present invention solves such a problem, and its object is to include binary data which the target CPU does not use as an instruction code in the address area which the target CPU refers to as an instruction code. Even if it is not affected by it, each instruction code of the target CPU existing in the address area is transferred to the host CP.
It is intended that the operation of the target CPU can be simulated on the host CPU without any trouble by enabling the correct conversion into the U instruction sequence.

【0013】[0013]

【課題を解決するための手段】本発明は上記の目的を達
成するために、シミュレーション対象となるターゲット
CPUの動作をホストCPU上でシミュレーションする
CPUシミュレータであって、ホストCPU上でターゲ
ットCPUの動作をシミュレーションする前の段階で、
ターゲットCPUの機械語レベルの命令コードをまとめ
て解釈して、ターゲットCPUの動作をシミュレーショ
ンするためにホストCPU上で実行する命令の列を生成
するようにしたCPUシミュレータにおいて、ターゲッ
トCPUが命令コードとして参照するアドレス領域のバ
イナリデータを命令コードの配置が可能な全てのアドレ
スを基点として命令コードに解釈し、解釈されたターゲ
ットCPUの命令コードを、それをシミュレーションす
るホストCPUの命令列と、解釈された命令コードの次
にターゲットCPUが実行する命令コードのシミュレー
ションを行うホストCPUの命令列に制御を移す命令列
とから構成されたシミュレーション命令列に変換する変
換手段を備えるようにしている。
In order to achieve the above-mentioned object, the present invention is a CPU simulator for simulating the operation of a target CPU to be simulated on a host CPU, and the operation of the target CPU on the host CPU. Before simulating
In a CPU simulator configured to collectively interpret machine language level instruction codes of a target CPU and generate a sequence of instructions to be executed on a host CPU in order to simulate the operation of the target CPU, the target CPU serves as an instruction code. The binary data of the address area to be referred to is interpreted as an instruction code with all addresses where instruction codes can be arranged as a base point, and the interpreted instruction code of the target CPU is interpreted as an instruction string of the host CPU simulating the instruction code. After the instruction code, a conversion means for converting the instruction code executed by the target CPU into a simulation instruction string composed of an instruction string for transferring control to the instruction string of the host CPU for simulating the instruction code is provided.

【0014】また、前記変換手段は、その一構成例とし
て、前記アドレス領域における命令コードの配置が可能
な各アドレスを指標としてシミュレーション命令列の各
アドレスを値に持つアドレス変換テーブルを生成すると
共に、シミュレーション命令列中の、解釈された命令コ
ードの次にターゲットCPUが実行する命令コードのシ
ミュレーションを行うホストCPUの命令列に制御を移
す命令列として、解釈された命令コードの次にターゲッ
トCPUが実行する命令コードのアドレスに対応して前
記アドレス変換テーブルに格納されたアドレス先のホス
トCPUの命令列に分岐する命令列を生成する構成を有
している。
Further, the converting means, as one configuration example thereof, generates an address conversion table having each address of the simulation instruction sequence as a value using each address in which the instruction code can be arranged in the address area as an index. The target CPU executes next to the interpreted instruction code as an instruction sequence for transferring control to the instruction sequence of the host CPU that simulates the instruction code executed by the target CPU next to the interpreted instruction code in the simulation instruction sequence. The instruction sequence is branched to the instruction sequence of the host CPU at the address destination stored in the address conversion table corresponding to the address of the instruction code.

【0015】[0015]

【作用】本発明のCPUシミュレータにおいては、ホス
トCPU上でターゲットCPUの動作をシミュレーショ
ンする前の段階で、変換手段が、ターゲットCPUが命
令コードとして参照するアドレス領域のバイナリデータ
を命令コードの配置が可能な全てのアドレスを基点とし
て命令コードに解釈し、解釈されたターゲットCPUの
命令コードを、それをシミュレーションするホストCP
Uの命令列と、解釈された命令コードの次にターゲット
CPUが実行する命令コードのシミュレーションを行う
ホストCPUの命令列に制御を移す命令列とから構成さ
れたシミュレーション命令列に変換する。
In the CPU simulator of the present invention, before the simulation of the operation of the target CPU on the host CPU, the conversion means arranges the binary data in the address area referred to by the target CPU as the instruction code in the instruction code. A host CP that interprets an instruction code from all possible addresses and simulates the interpreted instruction code of the target CPU.
It is converted into a simulation instruction string composed of a U instruction string and an instruction string that transfers control to the instruction string of the host CPU that simulates the instruction code executed by the target CPU after the interpreted instruction code.

【0016】[0016]

【実施例】次に本発明の実施例について図面を参照して
詳細に説明する。
Embodiments of the present invention will now be described in detail with reference to the drawings.

【0017】図1は本発明の一実施例の概略構成図であ
り、ターゲットCPUが命令コードとして参照するター
ゲットプログラム中のアドレス領域のバイナリデータ1
から、CPUシミュレータの変換手段2が、ホストCP
Uのシミュレーション命令列で構成されるシミュレーシ
ョンコード3と、ターゲットCPU上の命令コードのア
ドレスとホストCPU上のシミュレーション命令列のア
ドレスとの対応関係を示すアドレス変換テーブル4とを
生成出力する様子を示している。
FIG. 1 is a schematic configuration diagram of an embodiment of the present invention. Binary data 1 of an address area in a target program referred to by a target CPU as an instruction code.
From the CPU simulator conversion means 2 to the host CP
The generation and output of the simulation code 3 including the U simulation instruction sequence and the address conversion table 4 indicating the correspondence between the address of the instruction code on the target CPU and the address of the simulation instruction sequence on the host CPU are shown. ing.

【0018】同図において、バイナリデータ1に示した
各番地0,1,2,…,n(各番地の記憶サイズは例え
ば1バイトとする)は、ターゲットCPUの命令コード
の配置が可能なアドレスを示している。図示の例では、
2バイトの命令コード1−1が0番地を先頭に配置さ
れ、同じく2バイトの命令コード1−2が2番地を先頭
に配置され、1バイトの命令コード1−3がn番地に配
置されているが、例えば1バイトの命令コードを0番地
を先頭に配置し、2バイトの命令コードを1番地を先頭
に配置することも可能であり、この意味で、各番地0,
1,2,…,nの何れもがターゲットCPUの命令コー
ドを配置できるアドレスとなる。
In the figure, each address 0, 1, 2, ..., N shown in the binary data 1 (the storage size of each address is, for example, 1 byte) is an address where the instruction code of the target CPU can be arranged. Is shown. In the example shown,
A 2-byte instruction code 1-1 is placed at address 0, a 2-byte instruction code 1-2 is placed at address 2, and a 1-byte instruction code 1-3 is placed at address n. However, for example, it is possible to arrange a 1-byte instruction code at the 0th address and a 2-byte instruction code at the 1st address. In this sense, each address 0,
Any of 1, 2, ..., N is an address where the instruction code of the target CPU can be arranged.

【0019】変換手段2は、バイナリデータ1を、命令
コードの配置が可能な全てのアドレスを基点として命令
コードに解釈し、解釈されたターゲットCPUの命令コ
ード毎にホストCPUのシミュレーション命令列を生成
する。即ち、変換手段2は、バイナリデータ1の0番地
から始まる命令コードを解釈してシミュレーション命令
列3−1を生成し、1番地から始まる命令コードを解釈
してシミュレーション命令列3−2を生成し、2番地か
ら始まる命令コードを解釈してシミュレーション命令列
3−3を生成し、以下同様の処理を行って、最後にn番
地から始まる命令コードを解釈してシミュレーション命
令列3−4を生成する。
The conversion means 2 interprets the binary data 1 into an instruction code based on all addresses in which the instruction code can be arranged, and generates a simulation instruction string of the host CPU for each interpreted instruction code of the target CPU. To do. That is, the conversion means 2 interprets the instruction code starting from the address 0 of the binary data 1 to generate the simulation instruction sequence 3-1 and interprets the instruction code starting from the address 1 to generate the simulation instruction sequence 3-2. , The simulation instruction sequence 3-3 is generated by interpreting the instruction code starting from the address 2, and the same process is performed thereafter, and the instruction code starting from the address n is finally interpreted to generate the simulation instruction sequence 3-4. .

【0020】ここで、図示の例のようにバイナリデータ
1の0番地を先頭に2バイトの命令コード1−1が存在
する場合には、0番地から始まる命令コードとして命令
コード1−1そのものが解釈され、命令コード1−1を
シミュレーションするホストCPUの命令列と、解釈さ
れた命令コード1−1の次にターゲットCPUが実行す
る命令コード(例えば命令コード1−2とする)のシミ
ュレーションを行うホストCPUの命令列に制御を移す
命令列とから構成されたシミュレーション命令列3−1
が生成される。同様に、バイナリデータ1に実際に存在
する他の命令コード1−2,1−3の先頭アドレスを基
点とする変換処理においては、実際に存在する命令コー
ド1−2,1−3そのものが解釈され、命令コード1−
2,1−3をシミュレーションするホストCPUの命令
列と、解釈された命令コード1−2,1−3の次にター
ゲットCPUが実行する命令コードのシミュレーション
を行うホストCPUの命令列に制御を移す命令列とから
構成されたシミュレーション命令列3−3,3−4が生
成される。なお、シミュレーションコード3に付記した
Address0等は各シミュレーション命令列3−1等が置か
れるホストCPU上でのアドレスを示す。
If there is a 2-byte instruction code 1-1 starting from address 0 of binary data 1 as in the illustrated example, the instruction code 1-1 itself is the instruction code starting from address 0. The instruction string of the host CPU that is interpreted and simulates the instruction code 1-1 and the instruction code (for example, instruction code 1-2) that the target CPU executes next to the interpreted instruction code 1-1 are simulated. Simulation instruction sequence 3-1 composed of an instruction sequence for transferring control to the instruction sequence of the host CPU
Is generated. Similarly, in the conversion process using the start addresses of the other instruction codes 1-2 and 1-3 actually existing in the binary data 1 as the base points, the actually existing instruction codes 1-2 and 1-3 themselves are interpreted. And the instruction code 1-
Control is transferred to the instruction sequence of the host CPU simulating 2, 1-3 and the instruction sequence of the host CPU simulating the instruction code executed by the target CPU next to the interpreted instruction code 1-2, 1-3. Simulation instruction sequences 3-3 and 3-4 composed of an instruction sequence are generated. In addition, it added to the simulation code 3.
Address 0 and the like indicate addresses on the host CPU where the simulation instruction strings 3-1 and the like are placed.

【0021】ここで、シミュレーション命令列3−1等
に含まれる、解釈された命令コードの次にターゲットC
PUが実行する命令コードのシミュレーションを行うホ
ストCPUの命令列に制御を移す命令列は、本実施例で
は、解釈された命令コードの次にターゲットCPUが実
行する命令コードのアドレスを指標としてアドレス変換
テーブル4を検索したときに得られるアドレスが指し示
すシミュレーションコード3のシミュレーション命令列
に分岐する命令列としている。
Here, the target C is next to the interpreted instruction code included in the simulation instruction sequence 3-1 or the like.
In the present embodiment, the instruction sequence for transferring control to the instruction sequence of the host CPU that simulates the instruction code executed by the PU is translated using the address of the instruction code executed by the target CPU next to the interpreted instruction code as an index. The instruction sequence branches to the simulation instruction sequence of the simulation code 3 indicated by the address obtained when the table 4 is searched.

【0022】他方、バイナリデータ1の1番地,3番地
などの如く、実際に存在する命令コードの先頭アドレス
でないアドレスを基点とする変換処理では、次の2通り
の命令コードに解釈される。
On the other hand, in the conversion process which uses an address other than the start address of the actually existing instruction code as the base point, such as the 1st address and the 3rd address of the binary data 1, it is interpreted as the following two instruction codes.

【0023】その1つは、その基点アドレス以降のバイ
ナリデータで、ターゲットCPUで定義された或る命令
コードが偶然に構成されることにより、そのような命令
コードに解釈される場合である。このような場合でも、
変換手段2は、その命令コードをシミュレーションする
ホストCPUの命令列と、その命令コードの次にターゲ
ットCPUが実行する命令コードのシミュレーションを
行うホストCPUの命令列に制御を移す命令列とから構
成されたシミュレーション命令列を生成する。これは、
そのような不正なアドレスに制御が移ったときのターゲ
ットCPUの動作をシミュレートできるようにするため
である。
One of them is a case where a certain instruction code defined by the target CPU is accidentally constructed by binary data after the base point address and is interpreted as such an instruction code. Even in this case,
The conversion means 2 is composed of an instruction sequence of the host CPU that simulates the instruction code and an instruction sequence that transfers control to the instruction sequence of the host CPU that simulates the instruction code executed by the target CPU next to the instruction code. Generate a simulation instruction sequence. this is,
This is to enable the operation of the target CPU when control is transferred to such an illegal address to be simulated.

【0024】他の1つは、その基点アドレス以降のバイ
ナリデータでは、ターゲットCPUで定義された命令コ
ードを構成せず、従って未定義命令コードと解釈される
場合である。このような場合、変換手段2においては、
この解釈した未定義命令コードに対応して、例えば未定
義命令コードが実行された旨のエラーメッセージを出力
するホストCPUの命令列を含むシミュレーション命令
列を生成する。また、未定義命令コードが実行されよう
とした場合、ターゲットCPUにおいて或る種の例外処
理が実行されるようになっている場合には、解釈した未
定義命令コードに対応して、その例外処理をシミュレー
ションするホストCPUの命令列を含むシミュレーショ
ン命令列を生成する。
The other one is a case where the binary data after the base address does not constitute an instruction code defined by the target CPU and is therefore interpreted as an undefined instruction code. In such a case, in the conversion means 2,
Corresponding to the interpreted undefined instruction code, for example, a simulation instruction sequence including an instruction sequence of the host CPU that outputs an error message indicating that the undefined instruction code has been executed is generated. Further, when an undefined instruction code is about to be executed, and if some sort of exception processing is to be executed on the target CPU, the exception processing is performed corresponding to the interpreted undefined instruction code. To generate a simulation instruction sequence including the instruction sequence of the host CPU simulating.

【0025】また、変換手段2は、上述のようなシミュ
レーション命令列3−1等で構成されるシミュレーショ
ンコード3を生成すると同時に、アドレス変換テーブル
4を生成する。このアドレス変換テーブル4は、ターゲ
ットCPUのバイナリデータ1の各番地を指標としシミ
ュレーション命令列3−1等の各アドレスを値に持つエ
ントリ4−1等の集合である。従って、図示の場合、タ
ーゲットCPUのバイナリデータ1の0番地に対してシ
ミュレーション命令列3−1のアドレスAddress0を持つ
エントリ4−1,1番地に対してシミュレーション命令
列3−2のアドレスAddress1を持つエントリ4−2,2
番地に対してシミュレーション命令列3−3のアドレス
Address2を持つエントリ4−3,…,n番地に対してシ
ミュレーション命令列3−4のアドレスAddress nを持
つエントリ4−4が生成される。
The conversion means 2 also generates the address conversion table 4 at the same time as generating the simulation code 3 composed of the above-mentioned simulation instruction sequence 3-1 and the like. The address conversion table 4 is a set of entries 4-1 and the like having each address of the binary data 1 of the target CPU as an index and each address of the simulation instruction sequence 3-1 and the like as a value. Therefore, in the illustrated case, the address 0 of the binary data 1 of the target CPU has the address Address0 of the simulation instruction sequence 3-1 and the entry 4-1 and the address Address1 of the simulation instruction sequence 3-2 for the address 1 of the target CPU. Entry 4-2, 2
Address of simulation instruction sequence 3-3 for address
The entry 4-4 having the address Address n of the simulation instruction sequence 3-4 is generated for the addresses 4-3, ..., N having the Address 2.

【0026】以上のようなシミュレーションコード3お
よびアドレス変換テーブル4の生成を終えると、実際の
シミュレーションが可能になる。本実施例におけるホス
トCPU上でのシミュレーション命令列の実行は、平成
5年2月26日提出の特許願(整理番号N0004S,
発明の名称;CPUシミュレーション方法およびCPU
シミュレータ)において提案された、アドレス変換テー
ブルを採用するCPUシミュレータと同様に進められ
る。
When the generation of the simulation code 3 and the address conversion table 4 as described above is completed, the actual simulation becomes possible. Execution of the simulation command sequence on the host CPU in this embodiment is performed by the patent application (reference number N0004S, filed on February 26, 1993).
Title of invention: CPU simulation method and CPU
(Simulator), the procedure is similar to that of the CPU simulator that employs the address conversion table.

【0027】即ち、例えばホストCPUがシミュレーシ
ョンコード3の例えばシミュレーション命令列3−1か
ら実行を開始したとすると、この命令列3−1中の、命
令コード1−1をシミュレーションするホストCPUの
命令列を実行することにより、命令コード1−1の動作
をシミュレーションし、次いでその命令列3−1中の、
命令コード1−1の次にターゲットCPUが実行する命
令コード1−2のシミュレーションを行うホストCPU
の命令列に制御を移す命令列を実行することにより、命
令コード1−2のターゲットCPU上でのアドレスであ
る2番地を指標にしてアドレス変換テーブル4からエン
トリ4−3を取得し、そのエントリ中のアドレスAddres
s2が指し示すシミュレーション命令列3−3に制御を移
す。以下、同様に、各シミュレーション命令列の実行に
より、バイナリデータ1中の各命令コードの動作をシミ
ュレーションし、シミュレーションした命令コードの次
の命令コードに対応したシミュレーション命令列に制御
を移すといった動作を繰り返し、ターゲットCPUの動
作をホストCPU上でシミュレーションする。
That is, if the host CPU starts execution from the simulation instruction sequence 3-1 of the simulation code 3, for example, the instruction sequence of the host CPU simulating the instruction code 1-1 in the instruction sequence 3-1. To simulate the operation of the instruction code 1-1, and then in the instruction sequence 3-1
A host CPU that simulates the instruction code 1-2 executed by the target CPU after the instruction code 1-1
By executing the instruction sequence for transferring the control to the instruction sequence No. 2, the entry 4-3 is acquired from the address conversion table 4 using the address 2 of the instruction code 1-2 on the target CPU as an index, and the entry Address in Addres
The control is transferred to the simulation instruction sequence 3-3 indicated by s2. Similarly, the operation of each instruction code in the binary data 1 is simulated by executing each simulation instruction string, and the operation is repeatedly transferred to the simulation instruction string corresponding to the instruction code next to the simulated instruction code. , Simulate the operation of the target CPU on the host CPU.

【0028】図2は上述した原理に基づくCPUシミュ
レータのより具体的な構成例を示すブロック図である。
この実施例のCPUシミュレータ5は、ターゲットプロ
グラム6をシミュレーション関数呼び出し列53に変換
すると共にアドレス変換テーブル56を生成する変換手
段50と、シミュレーション関数呼び出し列53,シミ
ュレーション関数群54,レジスタシミュレータ55お
よびアドレス変換テーブル56を格納するメモリ51
と、シミュレーション関数呼び出し列53等を実行する
ホストCPU52とを含んでいる。
FIG. 2 is a block diagram showing a more specific configuration example of the CPU simulator based on the above-mentioned principle.
The CPU simulator 5 of this embodiment converts a target program 6 into a simulation function call sequence 53 and generates an address conversion table 56, a simulation function call sequence 53, a simulation function group 54, a register simulator 55 and an address. Memory 51 for storing conversion table 56
And a host CPU 52 that executes the simulation function call sequence 53 and the like.

【0029】ターゲットプログラム6は、ターゲットC
PU用に開発されたプログラムであり、ターゲットCP
Uが命令コードとして参照するアドレス領域のバイナリ
データ60中には、ターゲットCPUのマシン語レベル
の命令コード6−1〜6−nが含まれている。ここで、
先頭の命令コード6−1は2バイト命令で、ターゲット
CPU上では0番地を先頭に配置され、次の命令コード
6−2は2番地を先頭に配置され、最後の命令コード6
−nはn番地に配置されている。
The target program 6 is the target C
A target CP that is a program developed for PU
The binary data 60 in the address area referred to by U as an instruction code includes instruction code 6-1 to 6-n at the machine language level of the target CPU. here,
The first instruction code 6-1 is a 2-byte instruction, and the 0th address is placed at the head on the target CPU, the next instruction code 6-2 is placed at the 2nd address, and the last instruction code 6
-N is located at address n.

【0030】シミュレーション関数呼び出し列53は、
変換手段50がターゲットプログラム6を処理して生成
したもので、図1のシミュレーションコード3に相当す
る。このシミュレーション関数呼び出し列53は、ホス
トCPU52のアセンブラ言語レベルまたはマシン語レ
ベルで表現されたシミュレーション関数呼び出し53−
1〜53−nで構成されている。ここで、先頭のシミュ
レーション関数呼び出し53−1はバイナリデータ60
の0番地から始まる命令コード6−1を変換したもの、
次のシミュレーション関数呼び出し53−2はバイナリ
データ60の1番地から始まる命令コード(ターゲット
CPUの或る種の命令コード或いは未定義命令コード)
を変換したもの、次のシミュレーション関数呼び出し5
3−3はバイナリデータ60の2番地から始まる命令コ
ード6−2を変換したもの、最後のシミュレーション関
数呼び出し53−nは命令コード6−nを変換したもの
であり、ホストCPU52のアドレス空間上ではメモリ
51のアドレスA,B,C,…,Nから始まる位置にそ
れぞれ格納されている。
The simulation function call sequence 53 is
The conversion means 50 processes and generates the target program 6, and corresponds to the simulation code 3 in FIG. The simulation function call sequence 53 is a simulation function call 53-expressed at the assembler language level or the machine language level of the host CPU 52.
1 to 53-n. Here, the simulation function call 53-1 at the head is the binary data 60.
Converted instruction code 6-1 starting from address 0 of
The next simulation function call 53-2 is an instruction code starting from the address 1 of the binary data 60 (a certain instruction code of the target CPU or an undefined instruction code).
Which is converted from the following simulation function call 5
3-3 is a conversion of the instruction code 6-2 starting from the address 2 of the binary data 60, and the last simulation function call 53-n is a conversion of the instruction code 6-n. In the address space of the host CPU 52, The addresses are stored in the memory 51 at positions starting from addresses A, B, C, ..., N, respectively.

【0031】アドレス変換テーブル56は、変換手段5
0がターゲットプログラム6を処理して生成したもの
で、例えば図3に示すように、ターゲットプログラム6
のバイナリデータ60の各番地0,1,2,…,nをイ
ンデックスとして、各番地から始まる命令コードに対応
するシミュレーション関数呼び出し53−1,53−
2,53−3,…,53−nのメモリ51上のアドレス
A,B,…,Nを保持している。
The address conversion table 56 is composed of the conversion means 5
0 is generated by processing the target program 6. For example, as shown in FIG.
, N of each of the binary data 60 of the above is used as an index, and the simulation function calls 53-1 and 53-corresponding to the instruction codes starting from the respective addresses are made.
, 53-n on the memory 51 are held.

【0032】シミュレーション関数群54は、シミュレ
ーション関数54−0〜54−mの集合である。このう
ち、シミュレーション関数54−1〜54−mはターゲ
ットCPUのマシン語レベルの各命令コードに1対1に
対応しており、対応するターゲットCPUの命令コード
をシミュレートする。シミュレーション関数54−0は
未定義命令コードと解釈された命令コードをシミュレー
トするための関数である。これらのシミュレーション関
数54−0〜54−mは例えばC言語で記述される。
The simulation function group 54 is a set of simulation functions 54-0 to 54-m. Of these, the simulation functions 54-1 to 54-m have a one-to-one correspondence with each instruction code at the machine language level of the target CPU, and simulate the instruction code of the corresponding target CPU. The simulation function 54-0 is a function for simulating an instruction code interpreted as an undefined instruction code. These simulation functions 54-0 to 54-m are described in C language, for example.

【0033】レジスタシミュレータ55は、ターゲット
CPU上のシミュレーション対象とするレジスタに1対
1に対応付けたレジスタの集まりであり、ホストCPU
52はこのレジスタシミュレータ55を参照,更新する
ことによりターゲットCPU上のレジスタをシミュレー
ションする。
The register simulator 55 is a collection of registers which are associated with the registers to be simulated on the target CPU in a one-to-one correspondence.
52 refers to and updates this register simulator 55 to simulate a register on the target CPU.

【0034】図2の実施例において、CPUシミュレー
タ5は、ターゲットプログラム6にかかるターゲットC
PUの動作のシミュレーションを実行する場合、シミュ
レーションの実行に先立って変換手段50を起動する。
In the embodiment shown in FIG. 2, the CPU simulator 5 uses the target C for the target program 6.
When executing the simulation of the operation of the PU, the conversion means 50 is activated prior to the execution of the simulation.

【0035】変換手段50は、例えば図4に示すよう
に、命令コード読み込み部501と命令解釈部502と
命令変換部503と出力部504,505とで構成され
ている。
As shown in FIG. 4, the converting means 50 is composed of an instruction code reading section 501, an instruction interpreting section 502, an instruction converting section 503, and output sections 504 and 505.

【0036】命令コード読み込み部501は図示しない
メモリやファイル等に格納された図2のターゲットプロ
グラム6中のバイナリデータ60を順次読み込み、命令
コードの配置が可能な全ての番地を基点として命令コー
ドに解釈し、解釈されたターゲットCPUの命令コード
を命令解釈部502に伝達する。
The instruction code reading unit 501 sequentially reads the binary data 60 in the target program 6 shown in FIG. 2 stored in a memory, a file, or the like (not shown), and uses all the addresses where the instruction codes can be arranged as base points for the instruction codes. The interpreted instruction code of the target CPU is transmitted to the instruction interpretation unit 502.

【0037】命令解釈部502は、命令コード読み込み
部501から伝達された命令コードがどのような命令な
のかを解釈し、命令の種類,命令に使用されるレジス
タ,メモリアドレス,定数等を判別し、判別結果を命令
変換部503に伝達する。
The instruction interpretation unit 502 interprets what kind of instruction the instruction code transmitted from the instruction code reading unit 501 is, and determines the type of instruction, the register used for the instruction, the memory address, the constant, and the like. The determination result is transmitted to the command conversion unit 503.

【0038】命令変換部503は、命令解釈部502か
ら伝達された判別結果に基づき、当該ターゲットCPU
のマシン語レベルの命令コードをシミュレートするため
のシミュレーション関数を呼び出すシミュレーション関
数呼び出しを、ホストCPU52のアセンブラ言語また
はマシン語レベルで生成する。
The instruction conversion unit 503 determines the target CPU based on the determination result transmitted from the instruction interpretation unit 502.
A simulation function call for calling a simulation function for simulating a machine language level instruction code is generated in the assembler language or machine language level of the host CPU 52.

【0039】例えば、ターゲットCPUがインテル社の
16ビットプロセッサ8086であり、ホストCPU5
2がMIPS社の32ビットプロセッサR3000であ
る場合、命令変換部503は、8086の命令コード
を、R3000で実行可能なシミュレーション関数を呼
び出すシミュレーション関数呼び出しを生成することに
なる。
For example, the target CPU is an Intel 16-bit processor 8086, and the host CPU 5
When 2 is a 32-bit processor R3000 manufactured by MIPS, the instruction conversion unit 503 generates a simulation function call that calls an instruction code of 8086 and calls a simulation function that can be executed by R3000.

【0040】以下に、8086の命令,R3000のシ
ミュレーション関数呼び出し,シミュレーション関数の
例を示す。なお、8086の命令とR3000のシミュ
レーション関数呼び出しとはアセンブラ表記で、R30
00のシミュレーション関数はC言語で示す。
The following is an example of the 8086 instruction, the R3000 simulation function call, and the simulation function. The 8086 instruction and the R3000 simulation function call are written in assembler notation R30.
The simulation function of 00 is shown in C language.

【0041】 ○8086の命令 MOV AX,0x1000 /*3バイト命令*/ ○シミュレーション関数呼び出し li a0,AX /*AXはレジスタを表す定数*/ li a1,0x1000 jal F_MOV /*シミュレーション関数の呼び出し*/ nop /*分岐遅延スロットを埋めるためのnop */ j v0 nop /*分岐遅延スロットを埋めるためのnop */ ○シミュレーション関数 F_MOV(reg,imm) int reg; short imm; { PC+=3; Reg[reg]=imm; /*Reg[]はレジスタ情 報を保持する変数*/ return(AddrTbl[(Reg[CS]<<4)+ PC]); /*AddrTbl[]はア ドレス変換テーブル56*/ }○ 8086 instruction MOV AX, 0x1000 / * 3-byte instruction * / ○ Simulation function call li a0, AX / * AX is a constant representing a register * / li a1, 0x1000 jal F_MOV / * Simulation function call * / nop / * nop for filling the branch delay slot * / j v0 nop / * nop for filling the branch delay slot * / ○ Simulation function F_MOV (reg, imm) int reg; short imm; {PC + = 3; Reg [ reg] = imm; / * Reg [] is a variable holding the register information * / return (AddrTbl [(Reg [CS] << 4) + PC]); / * AddrTbl [] is the address conversion table 56 * /}

【0042】上記のシミュレーション関数における return(AddrTbl[(Reg[CS]<<4)+PC]); は、8086で実行すべき命令のアドレス(Reg[C
S]<<4)+PCをインデックスとしてアドレス変換
テーブル56を参照してそのインデックスに対応するホ
ストCPU52上のアドレスを得てリターン値として返
却するもので、シミュレーション関数呼び出し側では、 j v0 を実行することにより、次にシミュレートすべき命令に
対応するシミュレーション関数呼び出し列53の部分へ
分岐する。
Return (AddrTbl [(Reg [CS] << 4) + PC]) in the above simulation function is the address of the instruction to be executed at 8086 (Reg [C
S] << 4) + PC is used as an index to refer to the address conversion table 56 to obtain the address on the host CPU 52 corresponding to the index and return it as a return value. At the simulation function calling side, j v0 is executed. As a result, the process branches to the portion of the simulation function call sequence 53 corresponding to the instruction to be simulated next.

【0043】また命令変換部503は、変換元の命令コ
ードが、レジスタ間接分岐,レジスタ間接サブルーチン
呼び出し等実行時まで分岐先アドレスのわからない命令
コードの場合、シミュレーションの結果得られたターゲ
ットCPU上での分岐先アドレスとアドレス変換テーブ
ル56の内容とから分岐すべきシミュレーション関数呼
び出し列53中のアドレスを求め且つそのアドレスに制
御を移すような命令列を含むシミュレーション関数を呼
び出すシミュレーション関数呼び出しに変換する。以下
に、8086のレジスタ間接分岐命令の例と、その変換
後のR3000のシミュレーション関数呼び出しの例
と、これによって呼び出されるR3000のシミュレー
ション関数の例とを示す。
When the instruction source code to be converted is an instruction code whose branch destination address is unknown until execution such as register indirect branching or register indirect subroutine calling, the instruction converting unit 503 executes the simulation on the target CPU. The address in the simulation function call sequence 53 to be branched is obtained from the branch destination address and the contents of the address conversion table 56, and is converted into a simulation function call that calls a simulation function including an instruction sequence that transfers control to the address. Below, an example of the register indirect branch instruction of 8086, an example of the simulation function call of R3000 after the conversion, and an example of the simulation function of R3000 called by this are shown.

【0044】 ○8086の命令 JMP [BX] /*2バイト命令*/ ○シミュレーション関数呼び出し li a0,BX /*BXはレジスタを表す定数*/ jal F_JMP_R /*シミュレーション関数の呼び出し*/ nop /*分岐遅延スロットを埋めるためのnop */ j v0 /*v0はF_JMP_R()のリターン値 */ nop /*分岐遅延スロットを埋めるためのnop */ ○シミュレーション関数 F_JMP_R(reg) int reg; { PC=Reg[reg]; return(AddrTbl[(Reg[CS]<<4)+ PC]); /*AddrTbl[]はアドレス変換テーブル56*/ }○ 8086 instruction JMP [BX] / * 2-byte instruction * / ○ Simulation function call lia0, BX / * BX is a constant representing a register * / jal F_JMP_R / * Simulation function call * / nop / * branch Nop * / j v0 / * v0 for filling the delay slot is the return value of F_JMP_R () * / nop / * nop * / for the purpose of filling the branch delay slot Simulation function F_JMP_R (reg) int reg; {PC = Reg [Reg]; return (AddrTbl [(Reg [CS] << 4) + PC]); / * AddrTbl [] is the address conversion table 56 * /}

【0045】即ち、JMP [BX]の場合、レジス
タBXを表す定数を引数としてシミュレーション関数F
_JMP_Rを呼び出すシミュレーション関数呼び出し
を生成する。シミュレーション関数F_JMP_Rで
は、 PC=Reg[reg]; により、8086上での分岐先のアドレスを保持してい
るレジスタの値(Reg[reg])をレジスタシミュ
レータ55から参照してレジスタシミュレータ55中の
PCの値を更新し、次いで、return(AddrT
bl[(Reg[CS]<<4)+PC]);を実行す
る。これは、8086で実行すべき命令のアドレスは、
セグメントレジスタ(ここではCS)とPCで指定され
るので、(Reg[CS]<<4)+PCにより808
6上でのアドレスを算出し、これをインデックスとして
アドレス変換テーブル56を参照し、得たアドレスをリ
ターン値として返却する。シミュレーション関数呼び出
し側では、 j v0 を実行することにより、次にシミュレートすべき命令に
対応するシミュレーション関数呼び出し列53の部分へ
分岐する。
That is, in the case of JMP [BX], the simulation function F is used with the constant representing the register BX as an argument.
Generate a simulation function call that calls _JMP_R. In the simulation function F_JMP_R, PC = Reg [reg]; is used to refer to the value (Reg [reg]) of the register holding the address of the branch destination on the 8086 from the register simulator 55 and PC in the register simulator 55. Update the value of return (AddrT
bl [(Reg [CS] << 4) + PC]); This is because the address of the instruction to be executed in 8086 is
Since it is specified by the segment register (CS in this case) and PC, (Reg [CS] << 4) + PC causes 808
The address on 6 is calculated, the address conversion table 56 is referenced using this as an index, and the obtained address is returned as a return value. On the simulation function call side, by executing j v0, the process branches to the part of the simulation function call sequence 53 corresponding to the instruction to be simulated next.

【0046】なお、命令変換部503は、実行前に分岐
先が確定している分岐命令コードの変換も行うが、本実
施例では、ターゲットCPUの命令コードのターゲット
CPU上でのアドレスに対応するシミュレーション関数
呼び出しのホストCPU上でのアドレスはアドレス変換
テーブル56によって求めることができるので、以下に
例示するような方法でシミュレーションしている。
The instruction conversion unit 503 also converts a branch instruction code whose branch destination is fixed before execution. In this embodiment, the instruction conversion unit 503 corresponds to the address of the instruction code of the target CPU on the target CPU. Since the address of the simulation function call on the host CPU can be obtained by the address conversion table 56, the simulation is performed by the method exemplified below.

【0047】 ○8086の命令 JMP 0x2000 /*2バイト命令*/ ○シミュレーション関数呼び出し li a0,0x2000 jal F_JMP /*シミュレーション関数の呼び出し*/ nop /*分岐遅延スロットを埋めるためのnop */ j v0 /*v0はF_JMP()のリターン値*/ nop /*分岐遅延スロットを埋めるためのnop */ ○シミュレーション関数 F_JMP(addr) unsigned short reg; { PC=addr; return(AddrTbl[(Reg[CS]<<4)+ PC]); /*AddrTbl[]はアドレス変換テーブル56*/ }○ 8086 instruction JMP 0x2000 / * 2-byte instruction * / ○ Simulation function call lia0, 0x2000 jal F_JMP / * Simulation function call * / nop / * nop * / j v0 / to fill the branch delay slot * V0 is the return value of F_JMP () * / nop / * nop for filling the branch delay slot * / ○ Simulation function F_JMP (addr) unsigned short reg; {PC = addr; return (AddrTbl [(Reg [CS] < <4) + PC]); / * AddrTbl [] is the address conversion table 56 * /}

【0048】さて、命令変換部503は、シミュレーシ
ョン関数呼び出しを生成すると、生成したシミュレーシ
ョン関数呼び出しを出力部504に伝達し、出力部50
4は、これを図2のメモリ51あるいは図示しない外部
記憶装置に順次格納する。
When the instruction conversion unit 503 generates the simulation function call, the instruction conversion unit 503 transmits the generated simulation function call to the output unit 504, and the output unit 50.
4 sequentially stores this in the memory 51 of FIG. 2 or an external storage device (not shown).

【0049】また、命令変換部503は、ターゲットプ
ログラム6のバイナリデータ60の各番地を基点とする
命令コードの変換を行うごとに出力部505を通じてメ
モリ51あるいは図示しない外部記憶装置にアドレス変
換テーブル56の1エントリを出力する。これにより、
ターゲットプログラム6のバイナリデータ60の全番地
を基点とする変換が完了した時点で、ターゲットプログ
ラム6のバイナリデータ60の各番地0,1,2,…,
nをインデックスとして、各番地から始まる命令コード
に対応するシミュレーション関数呼び出し53−1,5
3−2,53−3,…,53−nのメモリ51上のアド
レスA,B,C,…,Nを記録した図3の如きアドレス
変換テーブル56がメモリ51上あるいは図示しない外
部記憶装置に生成される。なお、外部記憶装置にアドレ
ス変換テーブル56が生成された場合、シミュレーショ
ンを開始する以前に外部記憶装置からメモリ51上へア
ドレス変換テーブル56を読み込む必要がある。
The instruction conversion unit 503 converts the instruction code from each address of the binary data 60 of the target program 6 as a base point, and outputs the address conversion table 56 to the memory 51 or an external storage device (not shown) through the output unit 505. 1 entry is output. This allows
When the conversion with all the addresses of the binary data 60 of the target program 6 as the base point is completed, each address of the binary data 60 of the target program 6, 0, 1, 2, ...
Simulation function call 53-1, 5 corresponding to the instruction code starting from each address with n as an index
Addresses A, B, C, ..., N on the memory 51 of 3-2, 53-3, ..., 53-n are stored in the memory 51 or an external storage device (not shown) as shown in FIG. Is generated. When the address conversion table 56 is generated in the external storage device, it is necessary to read the address conversion table 56 from the external storage device into the memory 51 before starting the simulation.

【0050】次に図2の実施例のシミュレーション実行
時の動作を説明する。
Next, the operation of the embodiment shown in FIG. 2 during the simulation will be described.

【0051】CPUシミュレータ5は、図示しない入力
手段からシミュレーションの実行開始の指示を受ける
と、シミュレーション関数呼び出し列53がマシン語レ
ベルで生成されているときは、ホストCPU52にメモ
リ51上のシミュレーション関数呼び出し列53を実行
させる。
When the CPU simulator 5 receives an instruction to start the execution of the simulation from the input means (not shown), when the simulation function call sequence 53 is generated at the machine language level, the host CPU 52 calls the simulation function on the memory 51. Execute column 53.

【0052】ホストCPU52は、先ずターゲットプロ
グラム6の実行開始番地に対応するシミュレーション関
数呼び出しを実行する。従って、シミュレーション関数
呼び出し53−1をターゲットプログラム6の実行開始
番地に対応するシミュレーション関数呼び出しとする
と、ホストCPU52は、先ずシミュレーション関数呼
び出し53−1を実行する。これにより、例えばシミュ
レーション関数54−1が呼び出されて実行され、命令
コード6−1がシミュレートされる。なお、この関数で
は、概ね以下のような処理が行われる。 (a)レジスタシミュレータ55中のPCの値を更新す
る。 (b)引数で指定されたレジスタ,メモリの内容を参
照,更新し必要な処理を行う。 (c)必要ならば、PSWを変更する。 (d)分岐命令の場合、ホストCPU上での分岐先アド
レスを求める。 (e)リターン値を返却する。
The host CPU 52 first executes a simulation function call corresponding to the execution start address of the target program 6. Therefore, assuming that the simulation function call 53-1 is a simulation function call corresponding to the execution start address of the target program 6, the host CPU 52 first executes the simulation function call 53-1. Thereby, for example, the simulation function 54-1 is called and executed, and the instruction code 6-1 is simulated. In addition, in this function, the following processes are generally performed. (A) Update the PC value in the register simulator 55. (B) Refer to and update the contents of the register and memory specified by the argument and perform the necessary processing. (C) If necessary, change PSW. (D) In the case of a branch instruction, the branch destination address on the host CPU is obtained. (E) Return the return value.

【0053】シミュレーション関数54−1の実行が終
了すると、本実施例では制御が呼び出し元のシミュレー
ション関数呼び出し53−1に一旦戻り、リターン値の
示すアドレスに分岐する。これにより、次にシミュレー
トすべき命令に対応するシミュレーション関数呼び出し
列53中のシミュレーション関数呼び出し53−3に制
御が移される。
When the execution of the simulation function 54-1 is completed, control returns to the calling simulation function call 53-1 once in this embodiment, and branches to the address indicated by the return value. As a result, control is transferred to the simulation function call 53-3 in the simulation function call sequence 53 corresponding to the instruction to be simulated next.

【0054】以下、上述の動作の繰り返しによりシミュ
レーション関数群54中の該当するシミュレーション関
数54−1〜54−mが呼び出されることにより、ター
ゲットプログラム6にかかるターゲットCPUの動作が
ホストCPU52上でシミュレートされる。
Hereinafter, by repeating the above-mentioned operation, the corresponding simulation functions 54-1 to 54-m in the simulation function group 54 are called to simulate the operation of the target CPU according to the target program 6 on the host CPU 52. To be done.

【0055】なお、シミュレーションの実行において、
ターゲットプログラム6のバイナリデータ60における
本来の命令コードの先頭アドレスでないアドレス、例え
ば1番地に制御が移行した場合でも、アドレス変換テー
ブル56を参照すると、そこにはシミュレーション関数
呼び出し53−2が設定されているので、このシミュレ
ーション関数呼び出し53−2が実行される。従って、
1番地を基点として解釈された命令コードがターゲット
CPUで定義された或る種の命令コードであった場合
は、シミュレーション関数呼び出し53−2はその命令
コードをシミュレートするシミュレーション関数を呼び
出すように生成されているため、その命令コードの動作
がシミュレーションされることになる。また、未定義命
令コードであった場合は、シミュレーション関数呼び出
し53−2は未定義命令実行時のシミュレーション処理
を行うシミュレーション関数54−0を呼び出すように
生成されているため、未定義命令実行時の動作がシミュ
レートされることになる。このように、本実施例によれ
ば、ターゲットプログラム6が不正なアドレスに制御を
移したときのターゲットCPUの動作もシミュレーショ
ンすることができる。
In executing the simulation,
Even if the control shifts to an address other than the start address of the original instruction code in the binary data 60 of the target program 6, for example, the control shifts to the first address, referring to the address conversion table 56, the simulation function call 53-2 is set there. Therefore, this simulation function call 53-2 is executed. Therefore,
If the instruction code interpreted from the first address is a certain instruction code defined in the target CPU, the simulation function call 53-2 is generated so as to call the simulation function that simulates the instruction code. Therefore, the operation of the instruction code is simulated. If it is an undefined instruction code, the simulation function call 53-2 is generated so as to call the simulation function 54-0 that performs the simulation processing at the time of execution of the undefined instruction. The behavior will be simulated. As described above, according to this embodiment, it is possible to simulate the operation of the target CPU when the target program 6 transfers control to an illegal address.

【0056】以上、本発明の実施例について説明した
が、本発明は以上の実施例にのみ限定されずその他各種
の付加変更が可能である。例えば、上記の実施例では変
換手段をホストCPUとは別に備えるようにしたが、ホ
ストCPUの機能で変換手段を実現するようにしても良
い。更に、以下のようにすることも可能である。
Although the embodiments of the present invention have been described above, the present invention is not limited to the above embodiments and various other additions and modifications can be made. For example, although the conversion means is provided separately from the host CPU in the above embodiment, the conversion means may be realized by the function of the host CPU. Further, it is possible to do the following.

【0057】ターゲットCPUの命令コードをシミュレ
ーション関数呼び出しに変換するのではなく、平成4年
12月29日提出の特許願(整理番号N0002S,発
明の名称;CPUシミュレーション方法およびCPUシ
ミュレータ)と同様に、各命令コードをシミュレートす
るホストCPUのアセンブラ言語レベルまたはマシン語
レベルの命令コードの組み合わせで表現されたコードに
変換する。
Instead of converting the instruction code of the target CPU into a simulation function call, as in the patent application (reference number N0002S, title of invention; CPU simulation method and CPU simulator) filed on December 29, 1992, Each instruction code is converted into a code expressed by a combination of assembler language level or machine language level instruction codes of the host CPU.

【0058】ターゲットCPUの命令コードを、平成5
年2月26日提出の特許願(整理番号N0004S,発
明の名称;CPUシミュレーション方法およびCPUシ
ミュレータ)と同様に、命令コードのバイト数の定数倍
のバイト数で構成されるシミュレーション関数呼び出し
に変換する。なお、このような構成では、或る命令コー
ドの次にターゲットCPUが実行する命令コードのシミ
ュレーションを行うホストCPUの命令列のアドレスは
計算によって求めることができるので、アドレス変換テ
ーブルは不要となる。
The instruction code of the target CPU is
Similar to the patent application (reference number N0004S, title of invention; CPU simulation method and CPU simulator) filed on February 26, 2014, conversion to a simulation function call composed of a constant number of bytes of the instruction code. . In such a configuration, since the address of the instruction string of the host CPU that simulates the instruction code executed by the target CPU after a certain instruction code can be calculated, the address conversion table becomes unnecessary.

【0059】[0059]

【発明の効果】以上説明したように本発明のCPUシミ
ュレータによれば、以下のような効果を得ることができ
る。
As described above, according to the CPU simulator of the present invention, the following effects can be obtained.

【0060】ターゲットCPUが命令コードとして参照
するアドレス領域のバイナリデータを命令コードの配置
が可能な全てのアドレスを基点として命令コードに解釈
してシミュレーション命令列に変換するため、アドレス
領域中にターゲットCPUが命令コードとして使用しな
いバイナリデータが混在している場合であっても、その
ようなバイナリデータとは無関係に、シミュレーション
の対象となる命令コードを確実にシミュレーション命令
列に変換することができる。そして、シミュレーション
命令列として、解釈されたターゲットCPUの命令コー
ドをシミュレーションするホストCPUの命令列と、解
釈された命令コードの次にターゲットCPUが実行する
命令コードのシミュレーションを行うホストCPUの命
令列に制御を移す命令列とから構成されたシミュレーシ
ョン命令列を生成するようにしたので、通常の場合、タ
ーゲットCPUが命令コードとして使用しないバイナリ
データを基点として解釈された命令コードに対応して生
成されたシミュレーション命令列に制御が移ることはな
く、ターゲットCPUの動作をホストCPU上で支障な
くシミュレーションすることができる。
Since the binary data in the address area referred to by the target CPU as an instruction code is converted into a simulation instruction sequence by interpreting the binary data in the address area as an instruction code based on all the addresses where instruction codes can be arranged, the target CPU is included in the address area. Even if there is a mixture of binary data that is not used as an instruction code, the instruction code to be simulated can be surely converted into a simulation instruction string regardless of such binary data. Then, as the simulation instruction sequence, there are an instruction sequence of the host CPU that simulates the interpreted instruction code of the target CPU and an instruction sequence of the host CPU that simulates the instruction code executed by the target CPU next to the interpreted instruction code. Since the simulation instruction sequence composed of the instruction sequence for transferring the control is generated, in the normal case, it is generated corresponding to the instruction code interpreted based on the binary data that the target CPU does not use as the instruction code. The control is not transferred to the simulation command sequence, and the operation of the target CPU can be simulated on the host CPU without any trouble.

【0061】シミュレーション対象となるターゲットプ
ログラムが、命令として使用しないバイナリデータのア
ドレスや数バイト命令コードの途中のバイトのアドレス
といった不正なアドレスに制御を移した場合、本発明で
は、そのような不正なアドレスに対してもそれを基点と
して命令コードを解釈してシミュレーション命令列を生
成してあるので、ターゲットCPUが不正なアドレスに
制御を移したときの動作もシミュレーションすることが
できるという効果もある。
When the target program to be simulated transfers control to an illegal address such as an address of binary data that is not used as an instruction or an address of a byte in the middle of an instruction code of several bytes, the present invention makes such an illegal address. Since the instruction code is also interpreted with respect to the address as the base point to generate the simulation instruction sequence, there is also an effect that the operation when the target CPU transfers control to an illegal address can be simulated.

【図面の簡単な説明】[Brief description of drawings]

【図1】本発明の一実施例の概略構成図であるFIG. 1 is a schematic configuration diagram of an embodiment of the present invention.

【図2】本発明のCPUシミュレータの一実施例のブロ
ック図である。
FIG. 2 is a block diagram of an embodiment of a CPU simulator of the present invention.

【図3】アドレス変換テーブルの内容例を示す図であ
る。
FIG. 3 is a diagram showing an example of contents of an address conversion table.

【図4】変換手段の構成例を示すブロック図である。FIG. 4 is a block diagram showing a configuration example of a conversion unit.

【図5】ターゲットCPUが命令コードとして参照する
アドレス領域のバイナリデータ中にターゲットCPUが
命令コードとして使わないバイナリデータが混在してい
るときに生じる問題点の説明図である。
FIG. 5 is an explanatory diagram of a problem that occurs when binary data that the target CPU does not use as an instruction code is mixed in binary data of an address area that the target CPU refers to as an instruction code.

【符号の説明】[Explanation of symbols]

1…ターゲットCPUが命令コードとして参照するアド
レス領域中のバイナリデータ 1−1〜1−3…命令コード 2…変換手段 3…ホストCPUが実行するシミュレーションコード 3−1〜3−4…シミュレーション命令列 4…アドレス変換テーブル 4−1〜4−4…エントリ
1 ... Binary data in address area referred to by target CPU as instruction code 1-1 to 1-3 ... Instruction code 2 ... Conversion means 3 ... Simulation code executed by host CPU 3-1 to 3-4 ... Simulation instruction string 4 ... Address conversion table 4-1 to 4-4 ... Entry

Claims (2)

【特許請求の範囲】[Claims] 【請求項1】 シミュレーション対象となるターゲット
CPUの動作をホストCPU上でシミュレーションする
CPUシミュレータであって、ホストCPU上でターゲ
ットCPUの動作をシミュレーションする前の段階で、
ターゲットCPUの機械語レベルの命令コードをまとめ
て解釈して、ターゲットCPUの動作をシミュレーショ
ンするためにホストCPU上で実行する命令の列を生成
するようにしたCPUシミュレータにおいて、 ターゲットCPUが命令コードとして参照するアドレス
領域のバイナリデータを命令コードの配置が可能な全て
のアドレスを基点として命令コードに解釈し、解釈され
たターゲットCPUの命令コードを、それをシミュレー
ションするホストCPUの命令列と、解釈された命令コ
ードの次にターゲットCPUが実行する命令コードのシ
ミュレーションを行うホストCPUの命令列に制御を移
す命令列とから構成されたシミュレーション命令列に変
換する変換手段を備えたことを特徴とするCPUシミュ
レータ。
1. A CPU simulator for simulating an operation of a target CPU to be simulated on a host CPU, which is a stage before simulating an operation of the target CPU on the host CPU.
In a CPU simulator configured to collectively interpret machine language level instruction codes of a target CPU and generate a sequence of instructions to be executed on a host CPU in order to simulate the operation of the target CPU, the target CPU serves as an instruction code. The binary data of the address area to be referred to is interpreted as an instruction code with all addresses where instruction codes can be arranged as a base point, and the interpreted instruction code of the target CPU is interpreted as an instruction string of the host CPU simulating the instruction code. And a conversion means for converting into a simulation instruction sequence composed of an instruction sequence for transferring control to the instruction sequence of the host CPU for simulating the instruction code executed by the target CPU Simulator.
【請求項2】 前記変換手段は、前記アドレス領域にお
ける命令コードの配置が可能な各アドレスを指標として
シミュレーション命令列の各アドレスを値に持つアドレ
ス変換テーブルを生成すると共に、シミュレーション命
令列中の、解釈された命令コードの次にターゲットCP
Uが実行する命令コードのシミュレーションを行うホス
トCPUの命令列に制御を移す命令列として、解釈され
た命令コードの次にターゲットCPUが実行する命令コ
ードのアドレスに対応して前記アドレス変換テーブルに
格納されたアドレス先のホストCPUの命令列に分岐す
る命令列を生成する構成を有する請求項1記載のCPU
シミュレータ。
2. The conversion means generates an address conversion table having, as an index, each address of a simulation instruction sequence with each address at which an instruction code can be arranged in the address area as an index, and in the simulation instruction sequence, Target CP next to the interpreted instruction code
U is stored in the address conversion table corresponding to the address of the instruction code executed by the target CPU next to the interpreted instruction code, as an instruction string for transferring control to the instruction string of the host CPU that simulates the instruction code executed by U 2. The CPU according to claim 1, having a configuration for generating an instruction sequence that branches to an instruction sequence of the host CPU at the specified address destination.
Simulator.
JP5136597A 1993-05-15 1993-05-15 CPU simulator Expired - Fee Related JP2788839B2 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP5136597A JP2788839B2 (en) 1993-05-15 1993-05-15 CPU simulator

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP5136597A JP2788839B2 (en) 1993-05-15 1993-05-15 CPU simulator

Publications (2)

Publication Number Publication Date
JPH06324883A true JPH06324883A (en) 1994-11-25
JP2788839B2 JP2788839B2 (en) 1998-08-20

Family

ID=15179023

Family Applications (1)

Application Number Title Priority Date Filing Date
JP5136597A Expired - Fee Related JP2788839B2 (en) 1993-05-15 1993-05-15 CPU simulator

Country Status (1)

Country Link
JP (1) JP2788839B2 (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005157640A (en) * 2003-11-25 2005-06-16 Mitsubishi Electric Corp Instruction simulation device, instruction simulation method and instruction simulation program
JP2009193446A (en) * 2008-02-15 2009-08-27 Nec Computertechno Ltd Information processor, emulation method in information processor, and emulation program
JP2011515750A (en) * 2008-03-17 2011-05-19 中国科学院▲計▼算技▲術▼研究所 RISC processor apparatus and method for supporting X86 virtual machine

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH01503181A (en) * 1987-03-24 1989-10-26 インシグニア・ソリューションズ・リミテッド Computer

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JPH01503181A (en) * 1987-03-24 1989-10-26 インシグニア・ソリューションズ・リミテッド Computer

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2005157640A (en) * 2003-11-25 2005-06-16 Mitsubishi Electric Corp Instruction simulation device, instruction simulation method and instruction simulation program
JP4563669B2 (en) * 2003-11-25 2010-10-13 三菱電機株式会社 Instruction simulator
JP2009193446A (en) * 2008-02-15 2009-08-27 Nec Computertechno Ltd Information processor, emulation method in information processor, and emulation program
JP2011515750A (en) * 2008-03-17 2011-05-19 中国科学院▲計▼算技▲術▼研究所 RISC processor apparatus and method for supporting X86 virtual machine

Also Published As

Publication number Publication date
JP2788839B2 (en) 1998-08-20

Similar Documents

Publication Publication Date Title
US5394544A (en) Software system debugger with distinct interrupt vector maps for debugging and application programs
EP0453394B1 (en) Dynamic process for the generation of biased pseudo-random test patterns for the functional verification of hardware designs
JP4050764B2 (en) Compilation system
JPH0628036B2 (en) Simulation method
JPH025139A (en) Simulation method
KR100537258B1 (en) Debug aid device, program compiler device, storage medium storing computer-readable debugger program and storage medium storing program compiler program
JP2788839B2 (en) CPU simulator
JP2817786B2 (en) Simulation apparatus and simulation method
KR0125605B1 (en) Method and device for verifying operation of machine language program
Larus Assemblers, linkers, and the SPIM simulator
JPH0668724B2 (en) Simulation method
JP2591418B2 (en) CPU simulator
JPH08305583A (en) Method for simulating cpu
JPH096646A (en) Program simulation device
WO2021140568A1 (en) Function generation program, function generation method, and information processing device
JP3745968B2 (en) Test system, test method, test program, and computer-readable recording medium recording the test program
JPH06202903A (en) Cpu simulation and cpu simulator
JP3324542B2 (en) Virtual machine
KARAPATEAS RETARGETING AN ASSEMBLY OPTIMIZER FOR THE MIPS/SCALE ASSEMBLY
Evans et al. Design of assembly level language for horizontal encoded microprogrammed control unit
JPH02110636A (en) Debugging device for tag architecture machine and its compiler
JP2009252170A (en) Converter and program conversion method
Feriozi AC programming model for OS/2 device drivers
JP2000242529A (en) Device and system for assisting program development and recording medium
JP2940976B2 (en) Specific character processor

Legal Events

Date Code Title Description
S531 Written request for registration of change of domicile

Free format text: JAPANESE INTERMEDIATE CODE: R313531

R350 Written notification of registration of transfer

Free format text: JAPANESE INTERMEDIATE CODE: R350

LAPS Cancellation because of no payment of annual fees