JP2591418B2 - CPU simulator - Google Patents
CPU simulatorInfo
- Publication number
- JP2591418B2 JP2591418B2 JP5063446A JP6344693A JP2591418B2 JP 2591418 B2 JP2591418 B2 JP 2591418B2 JP 5063446 A JP5063446 A JP 5063446A JP 6344693 A JP6344693 A JP 6344693A JP 2591418 B2 JP2591418 B2 JP 2591418B2
- Authority
- JP
- Japan
- Prior art keywords
- cpu
- simulation function
- address
- simulation
- target
- 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.)
- Expired - Lifetime
Links
- 238000004088 simulation Methods 0.000 claims description 302
- 230000006870 function Effects 0.000 claims description 297
- 238000006243 chemical reaction Methods 0.000 claims description 121
- 239000013256 coordination polymer Substances 0.000 claims description 11
- 238000012545 processing Methods 0.000 description 29
- 238000000034 method Methods 0.000 description 13
- 238000010586 diagram Methods 0.000 description 11
- 238000002360 preparation method Methods 0.000 description 6
- 230000007246 mechanism Effects 0.000 description 4
- 230000008569 process Effects 0.000 description 4
- 101100412394 Drosophila melanogaster Reg-2 gene Proteins 0.000 description 3
- 101150060453 LIA1 gene Proteins 0.000 description 3
- 238000004364 calculation method Methods 0.000 description 3
- 230000008859 change Effects 0.000 description 3
- 230000008901 benefit Effects 0.000 description 2
- 238000004891 communication Methods 0.000 description 2
- 108091036429 KCNQ1OT1 Proteins 0.000 description 1
- 230000005856 abnormality Effects 0.000 description 1
- 238000007792 addition Methods 0.000 description 1
- 230000006399 behavior Effects 0.000 description 1
- 230000015572 biosynthetic process Effects 0.000 description 1
- 238000012937 correction Methods 0.000 description 1
- 238000001514 detection method Methods 0.000 description 1
- 230000000694 effects Effects 0.000 description 1
- 238000011156 evaluation Methods 0.000 description 1
Landscapes
- Test And Diagnosis Of Digital Computers (AREA)
Description
【0001】[0001]
【産業上の利用分野】本発明は、ターゲットCPUの動
作をホストCPU上でシミュレートする技術に関する。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 Before a target machine including a target CPU is completed, or before debugging and performance evaluation on the target machine, a program developed for the target CPU (referred to as a target program) is debugged and performance is evaluated. As a method of performing the target CP, the target CP according to the target program is executed on a CPU simulator including a host CPU which is a CPU different from the target CPU.
There is a way to simulate the behavior of U,
An interpreter method for sequentially interpreting and executing a source program for a target CPU and an object simulation method for sequentially interpreting and executing a machine language code for a target CPU (for example, edited by the Handbook Committee of the Institute of Electronics, Information and Communication Engineers, Ohmsha Co., Ltd., published on March 30, 1988, 1st edition, "Electronic Information and Communication Handbook Second Volume," p. 1857, 5.3, "Simulator".
【0003】ここで、インタプリタ方式は、ターゲット
CPU用の原始プログラム(ソースプログラム)を直接
にインタプリートしつつシミュレートするものであり、
オブジェクトシミュレーション方式は、シミュレートに
先立ってターゲットプログラムの原始プログラム(ソー
スプログラム)をコンパイルまたはアセンブルしてター
ゲットCPUのマシン語レベルの命令コードに変換し、
この命令コードをシミュレートするものである。Here, the interpreter system simulates a source program for a target CPU while directly interpreting the source program.
In the object simulation method, a source program of a target program is compiled or assembled and converted into an instruction code at a machine language level of a target CPU prior to simulation.
This instruction code is simulated.
【0004】オブジェクトシミュレーション方式は、タ
ーゲットCPUのマシン語レベルの命令生成のための時
間がかかるが、シミュレートの実行時間はインタプリタ
方式に比べて速くなるため、短いシミュレート時間を要
求される場合にはオブジェクトシミュレーション方式が
用いられる。なお、ターゲットプログラムがマシン語レ
ベルで既に存在する場合には、コンパイルまたはアセン
ブルが不要であることは勿論のことである。In the object simulation method, it takes time to generate a machine-language-level instruction of the target CPU. However, the simulation execution time is faster than in the interpreter method, so that a short simulation time is required. Uses an object simulation method. If the target program already exists at the machine language level, it goes without saying that compilation or assembling is unnecessary.
【0005】そして、オブジェクトシミュレーション方
式のCPUシミュレータにおいては、例えば特開平2−
250122号公報に見られるように、ターゲットCP
Uの命令コードをホストCPU上で実行時に1命令ずつ
解釈しながらシミュレートを進めていた。In a CPU simulator of the object simulation system, for example, Japanese Patent Laid-Open No.
No. 250122, the target CP
The simulation has been performed while interpreting the instruction code of U one instruction at a time when executed on the host CPU.
【0006】このようにオブジェクトシミュレーション
方式のCPUシミュレータはインタプリタ方式のものに
比べてシミュレーション速度の点で優れているが、従来
のようにターゲットCPUの命令コードをホストCPU
上で実行時に1命令ずつ解釈する構成では、その解釈の
ために要する時間がシミュレーション時のオーバヘッド
となる。As described above, the object simulation type CPU simulator is superior to the interpreter type in terms of simulation speed. However, unlike the conventional one, the instruction code of the target CPU is stored in the host CPU.
In the above configuration in which instructions are interpreted one by one at the time of execution, the time required for the interpretation becomes an overhead during simulation.
【0007】そこで本発明者は、シミュレーション実行
時におけるターゲットCPUの命令コードの解釈を不要
にすることにより高速なシミュレーションを可能とした
新規なCPUシミュレータ(以下、既提案CPUシミュ
レータと称す)を、平成4年12月29日提出の特許願
(整理番号N0002S,発明の名称(CPUシミュレ
ーション方法およびCPUシミュレータ)において提案
した。Therefore, the present inventor has proposed a new CPU simulator (hereinafter referred to as a proposed CPU simulator) which enables high-speed simulation by eliminating the interpretation of the instruction code of the target CPU at the time of executing the simulation. This was proposed in a patent application (reference number N0002S, title of invention (CPU simulation method and CPU simulator)) filed on December 29, 4th.
【0008】この既提案CPUシミュレータは、ターゲ
ットCPUの動作をホストCPU上でシミュレートする
CPUシミュレータにおいて、ターゲットプログラムの
マシン語レベルの命令コードを事前にまとめて解釈し、
各命令コードをシミュレートするホストCPUのアセン
ブラ言語レベルまたはマシン語レベルの命令コードの組
み合わせで表現されたシミュレーションプログラムを生
成し、この生成したシミュレーションプログラムをホス
トCPUで実行するものであり、シミュレーション実行
時におけるターゲットCPUの命令コードの解釈が不要
になる為、その分、高速なシミュレーションが可能にな
る。This proposed CPU simulator is a CPU simulator that simulates the operation of a target CPU on a host CPU, interprets instruction codes at the machine language level of the target program in advance, and interprets them in advance.
A simulation program expressed by a combination of instruction codes at an assembler language level or a machine language level of a host CPU that simulates each instruction code is generated, and the generated simulation program is executed by the host CPU. Since it is not necessary to interpret the instruction code of the target CPU in (1), a high-speed simulation can be performed accordingly.
【0009】[0009]
【発明が解決しようとする課題】ところで、ターゲット
CPUの1つの命令コードをシミュレートするためのホ
ストCPUの命令コードの数は、ホストCPUにターゲ
ットCPUと同じ動作をする命令がある場合は基本的に
は1個で済むが、同じ動作をする命令がない場合は複数
個必要になる。このため、ターゲットプログラムをホス
トCPUの命令コード自体の集合であるシミュレーショ
ンプログラムに変換すると、一般に変換後のコード量は
多くなる。By the way, the number of instruction codes of the host CPU for simulating one instruction code of the target CPU is basically limited when the host CPU has an instruction which performs the same operation as the target CPU. Need only one, but if there is no instruction that performs the same operation, a plurality of instructions are required. For this reason, when the target program is converted into a simulation program which is a set of instruction codes of the host CPU itself, the code amount after the conversion generally increases.
【0010】変換後のコード量が多くなると、種々の問
題を招来する。例えば、ホストCPUの主記憶容量が小
さいとシミュレーションプログラムの実行が行えない場
合がある。またページングによる仮想記憶管理機構を使
用したホストCPUではページアウト回数の増加を招来
する。更に、キャッシュ機構を備えたホストCPUでは
キャッシュヒット率が低下する。これらは何れもシミュ
レーションの実行時間を長大化する要因となる。[0010] When the code amount after conversion increases, various problems are caused. For example, if the main storage capacity of the host CPU is small, it may not be possible to execute the simulation program. Also, the host CPU using the virtual memory management mechanism by paging increases the number of page-outs. Further, the cache hit rate is reduced in the host CPU having the cache mechanism. All of these factors increase the execution time of the simulation.
【0011】そこで本発明は、既提案CPUシミュレー
タを更に改良し、変換後のコード量を極力少なくし得る
ようにすることを目的としている。An object of the present invention is to further improve the already proposed CPU simulator so that the converted code amount can be minimized.
【0012】[0012]
【課題を解決するための手段】本発明のCPUシミュレ
ータは上記の目的を達成するために、シミュレーション
対象となるターゲットCPUの動作をホストCPU上で
シミュレートするCPUシミュレータにおいて、前記タ
ーゲットCPUのマシン語レベルの各命令コードをシミ
ュレートする、前記ホストCPUで実行可能なシミュレ
ーション関数を、前記ターゲットCPUのマシン語レベ
ルの命令コードの種類数分格納するシミュレーション関
数記憶手段と、前記ターゲットCPU用に開発されたタ
ーゲットプログラムのマシン語レベルの命令コードを解
釈して、前記ターゲットプログラムを、前記シミュレー
ション関数を呼び出すシミュレーション関数呼び出しの
集合であるシミュレーション関数呼び出し列に変換する
変換手段とを備え、該変換手段により生成されたシミュ
レーション関数呼び出し列を前記ホストCPUが実行す
ることにより、前記ターゲットプログラムにかかる前記
ターゲットCPUの動作のシミュレーションを行う構成
を有している。In order to achieve the above object, a CPU simulator of the present invention simulates the operation of a target CPU to be simulated on a host CPU. Simulation function storage means for storing as many simulation functions as can be executed by the host CPU for simulating each instruction code of the target CPU, for the number of machine language level instruction codes of the target CPU; Conversion means for interpreting a machine language level instruction code of the target program and converting the target program into a simulation function call sequence which is a set of simulation function calls for calling the simulation function. By the simulation function call string generated by said converting means and said host CPU executes, and has a configuration for simulating the operation of the target CPU according to the target program.
【0013】また、本発明は、レジスタ間接分岐,レジ
スタ間接サブルーチン呼び出し等、実行時まで分岐先ア
ドレスのわからない命令コードもシミュレーションし得
るようにするために、以下の(A)または(B)のよう
な構成を採用している。Further, the present invention provides the following (A) or (B) in order to simulate an instruction code whose branch destination address is not known until execution, such as register indirect branch, register indirect subroutine call, and the like. Configuration is adopted.
【0014】構成(A);前記変換手段は、前記ターゲ
ットプログラムのマシン語レベルの各命令コードを、該
命令コードのバイト数の定数倍のバイト数で構成される
シミュレーション関数呼び出しに変換する構成を備え、
実行時まで分岐先アドレスのわからない前記ターゲット
プログラムのマシン語レベルの命令コードに対応して、
レジスタのシミュレーションの結果得られたターゲット
CPU上での分岐先アドレスと前記定数倍の倍率とから
分岐すべきシミュレーション関数呼び出し列中のアドレ
スを計算によって求めてリターン値として返却するシミ
ュレーション関数を呼び出すと共に、該呼び出したシミ
ュレーション関数の終了時に前記リターン値の示すアド
レスに分岐するシミュレーション関数呼び出しを生成す
る構成。Configuration (A): The conversion means converts each instruction code at a machine language level of the target program into a simulation function call composed of a constant number of bytes of the instruction code. Prepared,
Corresponding to the machine language level instruction code of the target program whose branch destination address is not known until execution time,
A simulation function for calculating an address in a simulation function call sequence to be branched from the branch destination address on the target CPU obtained as a result of the simulation of the register and the magnification of the constant multiple and returning the return value as a return value, Generating a simulation function call that branches to an address indicated by the return value when the called simulation function ends.
【0015】構成(B);前記変換手段は、前記ターゲ
ットプログラムのマシン語レベルの各命令コードの前記
ターゲットCPU上のアドレスと、該命令コード変換後
の前記シミュレーション関数呼び出しの前記ホストCP
U上のアドレスとの対応を示すアドレス変換テーブルを
生成する構成を備え、前記ターゲットプログラムのマシ
ン語レベルの命令コードに対応して、レジスタのシミュ
レーションの結果得られたターゲットCPU上での次に
実行すべきアドレスと前記アドレス変換テーブルの内容
とから次に実行すべきシミュレーション関数呼び出し列
中のアドレスを求めてリターン値として返却するシミュ
レーション関数を呼び出すと共に、該呼び出したシミュ
レーション関数の終了時に前記リターン値の示すアドレ
スに分岐するシミュレーション関数呼び出しを生成する
構成。Configuration (B): The conversion means comprises an address on the target CPU of each instruction code at a machine language level of the target program, and the host CP of the simulation function call after the conversion of the instruction code.
A configuration for generating an address conversion table indicating a correspondence with an address on the U, and a next execution on a target CPU obtained as a result of register simulation in accordance with a machine language level instruction code of the target program From the address to be executed and the contents of the address conversion table, a simulation function to be executed is obtained as an address in a simulation function call sequence to be executed next, and a simulation function to be returned as a return value is called. A configuration for generating a simulation function call that branches to the indicated address.
【0016】更に、本発明は、デバッグ等を効率良く行
えるようにするために、上記(B)の構成のCPUシミ
ュレータにおいて、前記アドレス変換テーブル中の、前
記変換手段によって設定されたターゲットCPU上のア
ドレスに対応して、ブレークポイント処理関数といった
別の関数のアドレスを設定する構成や、前記変換手段に
よって設定されたターゲットCPU上のアドレス以外の
命令の存在しないアドレスに不正アドレス実行時処理関
数といった別の関数のアドレスを設定した構成を有して
いる。Further, according to the present invention, in order to enable efficient debugging and the like, in the CPU simulator having the configuration of the above (B), the CPU simulator in the address conversion table is provided on the target CPU set by the conversion means. A configuration in which an address of another function such as a breakpoint processing function is set in accordance with an address, or a different function such as an illegal address execution function at an address where no instruction other than the address on the target CPU set by the conversion means exists. The function address is set.
【0017】[0017]
【作用】本発明のCPUシミュレータにおいては、変換
手段が、シミュレーションの実行に先立ち、ターゲット
プログラムのマシン語レベルの命令コードをまとめて解
釈して、ターゲットプログラムを、その各命令コードを
シミュレートするホストCPUで実行可能なシミュレー
ション関数を呼び出すシミュレーション関数呼び出しの
集合であるシミュレーション関数呼び出し列に変換し、
ホストCPUがこの生成されたシミュレーション関数呼
び出し列を実行することにより、つまりシミュレーショ
ン関数記憶手段に保持された該当するシミュレーション
関数を実行することにより、ターゲットプログラムにか
かるターゲットCPUの動作のシミュレーションを行
う。In the CPU simulator according to the present invention, the conversion means interprets the instruction codes at the machine language level of the target program before executing the simulation, and simulates the target program with each instruction code. A simulation function call sequence, which is a set of simulation function calls for calling a simulation function executable by the CPU,
The host CPU simulates the operation of the target CPU according to the target program by executing the generated simulation function call sequence, that is, by executing the corresponding simulation function held in the simulation function storage means.
【0018】[0018]
【実施例】次に本発明の実施例について図面を参照して
詳細に説明する。DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS Next, embodiments of the present invention will be described in detail with reference to the drawings.
【0019】まず、本発明を適用したCPUシミュレー
タの基本的な構成について、図1および図2を参照して
説明する。図1を参照すると、本発明を適用したCPU
シミュレータ1の基本構成は、ターゲットプログラム2
をシミュレーション関数呼び出し列13に変換する変換
手段10と、シミュレーション関数呼び出し列13およ
びシミュレーション関数群14を格納するメモリ11
と、シミュレーション関数呼び出し列13およびシミュ
レーション関数群14を実行するホストCPU12とを
含んでいる。 First, a CPU simulation to which the present invention is applied
1 and 2 for the basic configuration of the
explain. Referring to FIG. 1, a CPU to which the present invention is applied
The basic configuration of the simulator 1 is the target program 2
Converting means 10 into a simulation function calling sequence 13 and a memory 11 storing the simulation function calling sequence 13 and the simulation function group 14
And a host CPU 12 that executes a simulation function calling sequence 13 and a simulation function group 14.
【0020】ターゲットプログラム2は、ターゲットC
PU(図示せず。以下同じ)用に開発されたプログラム
であり、ターゲットCPUのマシン語レベルの命令コー
ド2−1〜2−nで構成されている。The target program 2 includes a target C
This is a program developed for a PU (not shown; the same applies hereinafter), and is composed of instruction codes 2-1 to 2-n at the machine language level of the target CPU.
【0021】シミュレーション関数群14は、シミュレ
ーション関数14−1〜14−mの集合である。各シミ
ュレーション関数14−1〜14−mはターゲットCP
Uのマシン語レベルの各命令コードに1対1に対応して
おり、対応するターゲットCPUの命令コードをシミュ
レートする。各シミュレーション関数14−1〜14−
mは任意の言語で記述できるものであり、本例ではC言
語を使用している。The simulation function group 14 is a set of simulation functions 14-1 to 14-m. Each simulation function 14-1 to 14-m is a target CP
The instruction codes correspond to the instruction codes at the machine language level of U on a one-to-one basis, and simulate the instruction codes of the corresponding target CPU. Each simulation function 14-1 to 14-
m can be described in any language, and in this example , the C language is used.
【0022】CPUシミュレータ1は、ターゲットプロ
グラム2にかかるターゲットCPUの動作のシミュレー
ションを実行する場合、シミュレーションの実行に先立
って変換手段10を起動する。When simulating the operation of the target CPU according to the target program 2, the CPU simulator 1 activates the conversion means 10 before executing the simulation.
【0023】変換手段10は、ターゲットプログラム2
の各命令コード2−1〜2−nを順次読み込んで解釈
し、各命令コード2−1〜2−nを、そのシミュレート
を行うシミュレーション関数14−1〜14−mを呼び
出すシミュレーション関数呼び出し13−1〜13−n
に変換する。シミュレーション関数呼び出し13−1〜
13−nの記述言語としては、アセンブラ言語またはマ
シン語が使用される。The conversion means 10 converts the target program 2
Of the instruction codes 2-1 to 2-n are sequentially read and interpreted, and the instruction codes 2-1 to 2-n are simulated by calling simulation functions 14-1 to 14-m for simulating the instruction codes 2-1 to 2-n. -1 to 13-n
Convert to Simulation function call 13-1
As the description language of 13-n, assembler language or machine language is used.
【0024】例えば、命令コード2−1をシミュレート
するシミュレーション関数が14−1の場合、変換手段
10は、命令コード2−1をシミュレーション関数14
−1を呼び出すシミュレーション関数呼び出し13−1
に変換し、また、命令コード2−2をシミュレートする
シミュレーション関数が14−mの場合、命令コード2
−2をシミュレーション関数14−mを呼び出すシミュ
レーション関数呼び出し13−2に変換する。更に、命
令コード2−nが命令コード2−1と同じ命令コードで
あった場合は、命令コード2−nをシミュレーション関
数14−1を呼び出すシミュレーション関数呼び出し1
3−nに変換する。For example, when the simulation function for simulating the instruction code 2-1 is 14-1, the conversion means 10 converts the instruction code 2-1 into the simulation function 14-1.
Simulation function call 13-1 to call -1
If the simulation function for simulating the instruction code 2-2 is 14-m, the instruction code 2
-2 is converted into a simulation function call 13-2 for calling the simulation function 14-m. Further, when the instruction code 2-n is the same instruction code as the instruction code 2-1, the instruction code 2-n is converted into the simulation function call 1 that calls the simulation function 14-1.
Convert to 3-n.
【0025】そして、変換手段10は変換後のシミュレ
ーション関数呼び出し13−1〜13−nをシミュレー
ション関数呼び出し列13としてメモリ11あるいは図
示しない外部記憶装置に格納する。The conversion means 10 stores the converted simulation function calls 13-1 to 13-n as the simulation function call sequence 13 in the memory 11 or an external storage device (not shown).
【0026】CPUシミュレータ1は、変換手段10に
よってメモリ11上にシミュレーション関数呼び出し列
13が生成されると、シミュレーション関数呼び出し列
13がマシン語レベルで生成されているときは、ホスト
CPU12にメモリ11上のシミュレーション関数呼び
出し列13を実行させる。When the simulation function call sequence 13 is generated on the memory 11 by the conversion means 10, the CPU simulator 1 transmits the simulation function call sequence 13 to the host CPU 12 when the simulation function call sequence 13 is generated at the machine language level. Is executed.
【0027】ホストCPU12は、先ずターゲットプロ
グラムの実行開始番地に対応するシミュレーション関数
呼び出しを実行する。従って、シミュレーション関数呼
び出し13−1をターゲットプログラムの実行開始番地
に対応するシミュレーション関数呼び出しとすると、ホ
ストCPU12は、先ずシミュレーション関数呼び出し
13−1を実行する。これにより、上述した例ではシミ
ュレーション関数14−1が呼び出されて実行され、命
令コード2−1がシミュレートされる。The host CPU 12 first executes a simulation function call corresponding to the execution start address of the target program. Therefore, if the simulation function call 13-1 is a simulation function call corresponding to the execution start address of the target program, the host CPU 12 first executes the simulation function call 13-1. Thus, in the above-described example, the simulation function 14-1 is called and executed, and the instruction code 2-1 is simulated.
【0028】シミュレーション関数14−1の実行が終
了すると、ホストCPU12は次のシミュレーション関
数呼び出し14−2を実行する。これにより、上述した
例ではシミュレーション関数14−mが呼び出されて実
行され、命令コード2がシミュレートされる。When the execution of the simulation function 14-1 is completed, the host CPU 12 executes the next simulation function call 14-2. Thus, in the above-described example, the simulation function 14-m is called and executed, and the instruction code 2 is simulated.
【0029】以下、上述の動作の繰り返しによりシミュ
レーション関数群14中の該当するシミュレーション関
数14−1〜14−mが呼び出されることにより、ター
ゲットプログラム2にかかるターゲットCPUの動作が
ホストCPU12上でシミュレートされる。Subsequently, the corresponding simulation functions 14-1 to 14-m in the simulation function group 14 are called by repetition of the above-described operation, whereby the operation of the target CPU according to the target program 2 is simulated on the host CPU 12. Is done.
【0030】なお、シミュレーション関数呼び出し列1
3がアセンブラ言語レベルで生成されているときは、C
PUシミュレータ1はこれをアセンブルしてマシン語レ
ベルのシミュレーション関数呼び出し列を生成し、これ
をホストCPU12上で実行することによりシミュレー
ションを実行する。また、変換手段10によって出力さ
れたシミュレーション関数呼び出し列13が外部記憶装
置に格納されている場合、CPUシミュレータ1はその
外部記憶装置からシミュレーション関数呼び出し列をメ
モリ11上に読み込んだ後に実行を開始する。The simulation function call sequence 1
3 is generated at the assembler language level, C
The PU simulator 1 assembles this to generate a simulation function call sequence at a machine language level, and executes it on the host CPU 12 to execute a simulation. When the simulation function call sequence 13 output by the conversion means 10 is stored in the external storage device, the CPU simulator 1 starts execution after reading the simulation function call sequence from the external storage device into the memory 11. .
【0031】図2は変換手段10の構成例を示す機能ブ
ロック図であり、命令コード読み込み部101と命令解
釈部102と命令変換部103と出力部104とで構成
されている。FIG. 2 is a functional block diagram showing an example of the configuration of the conversion means 10, which comprises an instruction code reading unit 101, an instruction interpretation unit 102, an instruction conversion unit 103, and an output unit 104.
【0032】命令コード読み込み部101は、図示しな
いメモリやファイル等に格納された図1のターゲットプ
ログラム2をその先頭から順次1命令コードずつ読み込
んで命令解釈部102に伝達する。The instruction code reading unit 101 sequentially reads the target program 2 of FIG. 1 stored in a memory, a file, or the like (not shown) one instruction code at a time from the beginning, and transmits the instruction code to the instruction interpretation unit 102.
【0033】命令解釈部102は、命令コード読み込み
部101から伝達された命令コード即ちターゲットCP
U用のマシン語レベルの命令コードがどのような命令な
のかを解釈し、命令の種類,命令に使用されるレジス
タ,メモリアドレス,定数等を判別し、その判別結果を
命令変換部103に伝達する。The instruction interpreter 102 receives the instruction code transmitted from the instruction code reader 101, that is, the target CP.
It interprets what type of instruction code is at the machine language level for U, determines the type of instruction, registers, memory addresses, constants, etc. used for the instruction, and transmits the determination result to the instruction conversion unit 103. I do.
【0034】命令変換部103は、命令解釈部102か
ら伝達された判別結果に基づき、当該ターゲットCPU
のマシン語レベルの命令コードをシミュレートするため
のシミュレーション関数を呼び出すシミュレーション関
数呼び出しを、ホストCPU12のアセンブラ言語レベ
ルまたはマシン語レベルで生成する。The instruction conversion unit 103 determines the target CPU based on the determination result transmitted from the instruction interpretation unit 102.
A simulation function call for calling a simulation function for simulating a machine language level instruction code is generated at the assembler language level or the machine language level of the host CPU 12.
【0035】例えば、ターゲットCPUがインテル社の
16ビットプロセッサ8086であり、ホストCPU1
2がMIPS社の32ビットプロセッサR3000であ
る場合、命令変換部103は、8086の命令コード
を、R3000で実行可能なシミュレーション関数を呼
び出すシミュレーション関数呼び出しを生成することに
なる。For example, the target CPU is an Intel 16-bit processor 8086, and the host CPU 1
If 2 is a MIPS 32-bit processor R3000, the instruction conversion unit 103 generates a simulation function call that calls a simulation function that can execute the instruction code of 8086 in R3000.
【0036】以下に、8086の命令,R3000で実
行されるシミュレーション関数呼び出し,シミュレーシ
ョン関数の例を示す。なお、8086の命令とR300
0のシミュレーション関数呼び出しとはアセンブラ表記
で、R3000のシミュレーション関数はC言語とアセ
ンブラ言語とで示す。The following is an example of an instruction of 8086, a call of a simulation function executed by R3000, and a simulation function. Note that the 8086 instruction and R300
The simulation function call of 0 is expressed in assembler notation, and the simulation function of R3000 is expressed in C language and assembler language.
【0037】 ○8086の命令 MOV AX,0x1000 /*3バイト命令*/ ○シミュレーション関数呼び出し li a0,AX /*引数の準備(AXは定数値)*/ li a1,0x1000 /*引数の準備*/ jal F_MOV /*関数の呼び出し*/ ○シミュレーション関数 C言語の場合 F_MOV(reg,imm) int reg; short imm; { Reg[reg]=imm; /*Reg[]はレジスタ情 報を保持する変数*/ } アセンブラ言語の場合 .globl F_MOV .ent F_MOV F_MOV: sll a0,2 /*a0レジスタにはレジスタ 番号が入っている*/ li t0,Reg /*Regはレジスタ情報を保 持する配列*/ add t0,a0 sw a1,(t0) /*a1には転送する値が格納 されている*/ j ra .end F_MOV80 Instruction of 8086 MOV AX, 0x1000 / * 3 byte instruction * / シ ミ ュ レ ー シ ョ ン Simulation function call lia0, AX / * Argument preparation (AX is a constant value) * / li1, 0x1000 / * Argument preparation * / jal F_MOV / * Call function * / ○ Simulation function In C language F_MOV (reg, imm) int reg; short imm; {Reg [reg] = imm; / * Reg [] is a variable that holds register information * /} In assembler language .glob F_MOV .ent F_MOV F_MOV: sl a0,2 / * a0 register contains register number * / lit0, Reg / * Reg is an array that holds register information * / add t0, a0 sw a1, (t0) / * a1 Values that are stored * / j ra .end F_MOV
【0038】 ○8086の命令 ADD AX,BX ○シミュレーション関数呼び出し li a0,AX /*引数の準備(AXは定数値)*/ li a1,BX /*引数の準備*/ jal F_ADD /*関数の呼び出し*/ ○シミュレーション関数 C言語の場合 F_ADD(reg1,reg2) int reg1,reg2; { Reg[reg1]+=Reg[reg2]; if(Reg[reg1]==0){ PSW|=PSW_Z; /*PSWはステータスレジ スタ情報を保持する変数 *PSW_ZはZフラグを表 す定数 */ } if(Reg[reg1]&0x8000){ if(Reg[reg1]==0){ PSW|=PSW_S; /*PSW_SはSフラグを 表す定数*/ } ・ ・ ・ } アセンブラ言語の場合 .globl F_ADD .ent F_ADD F_ADD: sll a0,2 sll a1,2 /*a0,a1にはレジスタ番 号*/ li t0,Reg /*Regはレジスタ情報を保 持する配列*/ add t0,a0 li t1,Reg add t1,a1 lw t2,(t0) lw t3,(t1) add t2,t3 sw t2,(t0) li t4,PSW /*PSWの処理*/ lw t5,(t4) beqz t2,L1 ori t5,PSW_Z L1: andi t6,t2,0x8000 bne t6,0,L2 ori t5,PSW_S L2: ・ ・ ・ .end F_ADDThe instruction of 8086 ADD AX, BX The simulation function call lia0, AX / * Preparation of arguments (AX is a constant value) * / lia1, BX / * Preparation of arguments * / jarF_ADD / * Function call * / ○ Simulation function In case of C language F_ADD (reg1, reg2) int reg1, reg2; {Reg [reg1] + = Reg [reg2]; if (Reg [reg1] == 0) 0PSW | = PSW_Z; / * PSW is a variable that holds status register information * PSW_Z is a constant representing the Z flag * / {if (Reg [reg1] & 0x8000)} if (Reg [reg1] == 0)} PSW | = PSW_S; / * PSW_S Is a constant indicating the S flag * /}} 場合} In the assembler language .g obl F_ADD .ent F_ADD F_ADD: sl a0,2 sl a1,2 / * a0, a1 have register number * / lit0, Reg / * Reg is array holding register information * / add t0, a0 lit1 , Reg add t1, a1 lw t2, (t0) lw t3, (t1) add t2, t3 sw t2, (t0) lit 4, PSW / * PSW processing * / lw t5, (t4) beqz t2, L1 ori t5, PSW_Z L1: andi t6, t2, 0x8000 bne t6, 0, L2 ori t5, PSW_S L2:... end F_ADD
【0039】上述した具体例からわかるように、命令変
換部103は、命令解釈部102の判別結果に基づき、
パラメータ(引数)の準備を行う命令とシミュレーショ
ン関数を実際に呼び出す関数の呼び出しとを含むシミュ
レーション関数呼び出しを生成する。As can be seen from the specific example described above, the instruction conversion unit 103 determines
A simulation function call including an instruction for preparing parameters (arguments) and a function call that actually calls the simulation function is generated.
【0040】さて、命令変換部103は、シミュレーシ
ョン関数呼び出しを生成すると、生成したシミュレーシ
ョン関数呼び出しを出力部104に伝達し、出力部10
4は、これを図1のメモリ11あるいは図示しない外部
記憶装置に順次格納する。When the instruction conversion unit 103 generates a simulation function call, the instruction conversion unit 103 transmits the generated simulation function call to the output unit 104, and outputs the simulation function call to the output unit 104.
4 sequentially stores them in the memory 11 of FIG. 1 or an external storage device (not shown).
【0041】このとき命令変換部103は、今回のター
ゲットCPUの命令コードのターゲットCPU上でのア
ドレスと今回生成したホストCPU12のシミュレーシ
ョン関数呼び出しのホストCPU12上でのアドレス
(複数の命令コードで構成されるシミュレーション関数
呼び出しの場合は先頭の命令コードのアドレス)との関
係を内部のアドレス対応表103−1に登録する。At this time, the instruction conversion unit 103 stores the address of the current instruction code of the target CPU on the target CPU and the address of the currently generated simulation function call of the host CPU 12 on the host CPU 12 (consisting of a plurality of instruction codes). In the case of a simulation function call, the address of the first instruction code is registered in the internal address correspondence table 103-1.
【0042】このアドレス対応表103−1は実行前に
分岐先が確定している分岐命令コードの変換時に参照さ
れる。即ち、命令変換部103はターゲットCPUの命
令コードがアドレスXに分岐する分岐命令コードであっ
た場合、アドレスXが変換後のホストCPU12上では
どのアドレスに相当するかをアドレス対応表103−1
を調べることにより取得し、この取得した分岐先アドレ
スを引数としてシミュレーション関数に引き渡すシミュ
レーション関数呼び出しを生成する。なお、シミュレー
ション関数を呼び出さずにホストCPU12の分岐命令
に変換することも可能である。This address correspondence table 103-1 is referred to at the time of conversion of a branch instruction code whose branch destination is determined before execution. That is, when the instruction code of the target CPU is a branch instruction code that branches to the address X, the instruction conversion unit 103 determines which address the address X corresponds to on the converted host CPU 12 in the address correspondence table 103-1.
To generate a simulation function call that transfers the obtained branch destination address to the simulation function as an argument. It is also possible to convert to a branch instruction of the host CPU 12 without calling the simulation function.
【0043】但し、今回の分岐命令コードが未だ処理し
ていない後続の命令コードへ分岐する命令であった場
合、アドレス対応表103−1にはその部分のアドレス
対応関係が未だ登録されていない。この場合は、ダミー
の分岐先アドレスを設定したシミュレーション関数呼び
出しを内部の変換結果一時記憶手段103−2に記憶す
ると共にアドレス対応表103−1に今回の分岐命令コ
ードとシミュレーション関数呼び出し間のアドレス関係
を登録し、次いでその分岐先アドレスを確定し得る命令
コードが現れるまで、後続のターゲットCPUの命令コ
ードのシミュレーション関数呼び出しへの変換,その変
換結果の変換結果一時記憶手段103−2への格納およ
びアドレス対応表103−1へのアドレス関係の登録を
行い、分岐先アドレスが確定した時点で、上記ダミーの
分岐先アドレスを正しいアドレスに変更し、その修正後
のシミュレーション関数呼び出しとそれに続いて変換結
果一時記憶手段103−2に蓄えられている後続のシミ
ュレーション関数呼び出しとをまとめて出力部104に
送ってメモリ11あるいは外部記憶装置(図示せず)に
出力する。However, if the current branch instruction code is an instruction that branches to a subsequent instruction code that has not yet been processed, the address correspondence of that part has not been registered in the address correspondence table 103-1. In this case, the simulation function call in which the dummy branch destination address is set is stored in the internal conversion result temporary storage means 103-2, and the address correspondence between the current branch instruction code and the simulation function call is stored in the address correspondence table 103-1. And then converts the instruction code of the subsequent target CPU into a simulation function call, stores the conversion result in the conversion result temporary storage means 103-2 until an instruction code that can determine the branch destination address appears, and The address relation is registered in the address correspondence table 103-1. When the branch destination address is determined, the dummy branch destination address is changed to a correct address, and the simulation function call after the correction and the subsequent conversion result are converted. Subsequent systems stored in the temporary storage 103-2. Together with Interview configuration function call sent to the output unit 104 outputs to the memory 11 or the external storage device (not shown).
【0044】図3は本発明の一実施例のCPUシミュレ
ータの機能ブロック図である。この実施例のCPUシミ
ュレータ3は、ターゲットプログラム4をシミュレーシ
ョン関数呼び出し列33に変換する変換手段30と、シ
ミュレーション関数呼び出し列33,シミュレーション
関数群34およびレジスタシミュレータ35を格納する
メモリ31と、シミュレーション関数呼び出し列33お
よびシミュレーション関数群34を実行するホストCP
U32とを含んでいる。FIG. 3 is a functional block diagram of a CPU simulator according to one embodiment of the present invention. The CPU simulator 3 of this embodiment includes a conversion means 30 for converting the target program 4 into a simulation function call sequence 33, a memory 31 for storing the simulation function call sequence 33, the simulation function group 34 and the register simulator 35, and a simulation function call sequence. Host CP executing the column 33 and the simulation function group 34
U32.
【0045】ターゲットプログラム4は、ターゲットC
PU用に開発されたプログラムであり、ターゲットCP
Uのマシン語レベルの命令コード4−1〜4−nで構成
されている。ここで、先頭の命令コード4−1のサイズ
は1バイトであり、ターゲットCPU上ではアドレス0
番地に位置し、次の命令コード4−2のサイズは2バイ
トであり、ターゲットCPU上ではアドレス1番地から
位置し、最後の命令コード4−nは1バイトで、ターゲ
ットCPU上ではn番地に位置している。The target program 4 includes a target C
It is a program developed for PU and target CP
It is composed of U machine language level instruction codes 4-1 to 4-n. Here, the size of the first instruction code 4-1 is 1 byte, and the address 0 on the target CPU.
At the address, the size of the next instruction code 4-2 is 2 bytes, and it is located at address 1 on the target CPU, and the last instruction code 4-n is 1 byte at the address n on the target CPU. positioned.
【0046】シミュレーション関数呼び出し列33は、
変換手段30がターゲットプログラム4を処理して生成
したもので、ホストCPU32のアセンブラ言語レベル
またはマシン語レベルで表現されたシミュレーション関
数呼び出し33−1〜33−nで構成されている。ここ
で、先頭のシミュレーション関数呼び出し33−1は1
バイトの命令コード4−1を変換したもので、そのサイ
ズはN(Nは正の整数)バイトであり、ホストCPU3
2のアドレス空間上ではアドレスAから始まる位置に置
かれている。次のシミュレーション関数呼び出し33−
2は2バイトの命令コード4−2を変換したもので、そ
のサイズは2Nバイトで、直前のシミュレーション関数
呼び出し33−1に続くメモリ31の領域に格納され、
最後のシミュレーション関数呼び出し33−nは1バイ
トの命令コード4−nを変換したもので、そのサイズは
Nバイトであり、直前のシミュレーション関数呼び出し
(図示せず)に続くメモリ31の領域に格納されてい
る。The simulation function calling sequence 33 is
The conversion means 30 is generated by processing the target program 4 and includes simulation function calls 33-1 to 33-n expressed at the assembler language level or the machine language level of the host CPU 32. Here, the first simulation function call 33-1 is 1
The size of the instruction code 4-1 is converted to N (N is a positive integer) bytes.
In the address space of No. 2, it is located at a position starting from address A. Next simulation function call 33-
2 is a 2-byte instruction code 4-2 converted and has a size of 2N bytes, which is stored in the area of the memory 31 following the immediately preceding simulation function call 33-1.
The last simulation function call 33-n is obtained by converting a 1-byte instruction code 4-n, has a size of N bytes, and is stored in an area of the memory 31 following the immediately preceding simulation function call (not shown). ing.
【0047】即ち、本実施例においては、変換手段30
は、ターゲットプログラム4のマシン語レベルの各命令
コード4−1〜4−nを、変換元の命令コードのバイト
数の定数倍(N倍)のバイト数で構成されるシミュレー
ション関数呼び出し33−1〜33−nに変換する。That is, in this embodiment, the conversion means 30
Is a simulation function call 33-1 in which each instruction code 4-1 to 4-n at the machine language level of the target program 4 is constituted by a number of bytes that is a constant multiple (N times) of the number of bytes of the conversion source instruction code. ~ 33-n.
【0048】シミュレーション関数群34は、シミュレ
ーション関数34−1〜34−mの集合であり、例えば
C言語で記述されている。各シミュレーション関数34
−1〜34−mはターゲットCPUのマシン語レベルの
各命令コードに1対1に対応しており、対応するターゲ
ットCPUの命令コードをシミュレートする。The simulation function group 34 is a set of simulation functions 34-1 to 34-m, and is described in, for example, the C language. Each simulation function 34
-1 to 34-m correspond one-to-one to each instruction code at the machine language level of the target CPU, and simulate the corresponding instruction code of the target CPU.
【0049】レジスタシミュレータ35は、ターゲット
CPU上のシミュレーション対象とするレジスタに1対
1に対応付けたレジスタの集まりであり、ホストCPU
32はこのレジスタシミュレータ35を参照,更新する
ことによりターゲットCPU上のレジスタをシミュレー
ションする。The register simulator 35 is a set of registers associated with the registers to be simulated on the target CPU on a one-to-one basis.
32 simulates a register on the target CPU by referring to and updating this register simulator 35.
【0050】図3の実施例において、CPUシミュレー
タ3は、ターゲットプログラム4にかかるターゲットC
PUの動作のシミュレーションを実行する場合、シミュ
レーションの実行に先立って変換手段30を起動する。In the embodiment of FIG. 3, the CPU simulator 3 executes the target C
When performing the simulation of the operation of the PU, the conversion unit 30 is activated prior to the execution of the simulation.
【0051】変換手段30は、例えば図4に示すよう
に、命令コード読み込み部301と命令解釈部302と
命令変換部303と出力部304とで構成されており、
起動されると、先ず命令コード読み込み部301は図示
しないメモリやファイル等に格納された図3のターゲッ
トプログラム4をその先頭から順次1命令コードずつ読
み込んで命令解釈部302に伝達する。The conversion means 30 comprises an instruction code reading unit 301, an instruction interpretation unit 302, an instruction conversion unit 303, and an output unit 304, as shown in FIG. 4, for example.
When activated, first, the instruction code reading unit 301 sequentially reads the target program 4 of FIG. 3 stored in a memory or a file (not shown) one instruction code at a time from the beginning, and transmits the instruction program to the instruction interpretation unit 302.
【0052】命令解釈部302は、命令コード読み込み
部301から伝達された命令コードがどのような命令な
のかを解釈し、命令の種類,命令に使用されるレジス
タ,メモリアドレス,定数等を判別し、判別結果を命令
変換部303に伝達する。The instruction interpreting unit 302 interprets what kind of instruction the instruction code transmitted from the instruction code reading unit 301 is, and determines the type of instruction, a register used for the instruction, a memory address, a constant, and the like. , And transmits the determination result to the instruction conversion unit 303.
【0053】命令変換部303は、命令解釈部302か
ら伝達された判別結果に基づき、当該ターゲットCPU
のマシン語レベルの命令コードをシミュレートするため
のシミュレーション関数を呼び出すシミュレーション関
数呼び出しを、ホストCPU32のアセンブラ言語また
はマシン語レベルで生成する。The instruction conversion unit 303 determines the target CPU based on the determination result transmitted from the instruction interpretation unit 302.
A simulation function call for calling a simulation function for simulating a machine language level instruction code is generated in an assembler language of the host CPU 32 or a machine language level.
【0054】例えば、ターゲットCPUがインテル社の
16ビットプロセッサ8086であり、ホストCPU3
2がMIPS社の32ビットプロセッサR3000であ
る場合、命令変換部303は、8086の命令コード
を、R3000が実行可能なシミュレーション関数を呼
び出すシミュレーション関数呼び出しを生成することに
なる。For example, the target CPU is an Intel 16-bit processor 8086, and the host CPU 3
In the case where 2 is a MIPS 32-bit processor R3000, the instruction conversion unit 303 generates a simulation function call for calling the instruction function of 8086 with a simulation function executable by R3000.
【0055】このとき、命令変換部303は、変換後の
シミュレーション関数呼び出しが変換元の命令コードの
N倍のバイト数になるように調整する。即ち、前述した
ように、1バイトの命令コード4−1,4−nはNバイ
トのシミュレーション関数呼び出し33−1,33−n
に、2バイトの命令コード4−2は2Nバイトのシミュ
レーション関数呼び出し33−2にというように、iバ
イトの命令をiNバイトのシミュレーション関数呼び出
しに変換する。これは、予め最適なNの値を決めてお
き、生成したシミュレーション関数呼び出しのバイト数
が元の命令コードのバイト数のN倍に一致していれば、
その生成したシミュレーション関数呼び出しそのものを
結果とし、N倍に満たなければ、満たない部分にNOP
命令等の如き実質的に何の処理も行わない命令を付け足
すことで実現する。At this time, the instruction conversion unit 303 adjusts the converted simulation function call so that the number of bytes is N times the number of the conversion source instruction code. That is, as described above, the 1-byte instruction codes 4-1 and 4-n are converted into N-byte simulation function calls 33-1 and 33-n.
The 2-byte instruction code 4-2 converts an i-byte instruction into an iN-byte simulation function call, such as a 2N-byte simulation function call 33-2. This is because an optimum value of N is determined in advance, and if the number of bytes of the generated simulation function call matches N times the number of bytes of the original instruction code,
As a result, the generated simulation function call itself is used as a result.
This is realized by adding an instruction such as an instruction that does not perform any processing.
【0056】以下に、上記Nが16であるときの、80
86の命令,R3000で実行可能なシミュレーション
関数呼び出し,シミュレーション関数の例を示す。な
お、8086の命令とR3000のシミュレーション関
数呼び出しとはアセンブラ表記で、R3000のシミュ
レーション関数はC言語で示す。Hereinafter, when the above N is 16,
86 shows an example of an instruction 86, a simulation function call executable by R3000, and a simulation function. The instruction of 8086 and the simulation function call of R3000 are expressed in assembler notation, and the simulation function of R3000 is expressed in C language.
【0057】 ○8086の命令 MOV AX,0x1000 /*3バイト命令*/ ○シミュレーション関数呼び出し li a0,AX /*引数の準備(AXはレジスタを表す定数 )*/ li a1,0x1000 /*引数の準備*/ jal F_MOV /*シミュレーション関数の呼び出し*/ nop /*定数倍にするためのnop命令*/ nop nop nop nop nop nop nop nop ○シミュレーション関数 F_MOV(reg,imm) int reg; short imm; { PC+=3; Reg[reg]=imm; /*Reg[reg]はレジ スタ情報を保持する変数*/ }80 Instruction of 8086 MOV AX, 0x1000 / * 3 byte instruction * / シ ミ ュ レ ー シ ョ ン Simulation function call lia0, AX / * Preparation of arguments (AX is a constant representing a register) * / lia1, 0x1000 / * Preparation of arguments * / Jar F_MOV / * Call of simulation function * / nop / * nop instruction for multiplying by a constant * / nop nop nop nop nop nop nop o Simulation function F_MOV (reg, imm) int reg; = 3; Reg [reg] = imm; / * Reg [reg] is a variable that holds register information * /}
【0058】また命令変換部303は、変換元の命令コ
ードが、レジスタ間接分岐,レジスタ間接サブルーチン
呼び出し等実行時まで分岐先アドレスのわからない命令
コードの場合、レジスタシミュレータ35中のターゲッ
トCPU上での分岐先アドレスを保持しているレジスタ
の内容(アドレスXとする)と倍率Nとから、分岐すべ
きシミュレーション関数呼び出し列中のアドレスを、 シミュレーション関数呼び出し列33の先頭アドレス+
(N×X) によって求め且つそのアドレスに制御を移すような命令
列を含むシミュレーション関数を呼び出すシミュレーシ
ョン関数呼び出しに変換する。以下に、8086のレジ
スタ間接分岐命令の例と、その変換後のR3000のシ
ミュレーション関数呼び出しの例と、これによって呼び
出されるR3000のシミュレーション関数の例とを示
す。When the instruction code of the conversion source is an instruction code whose branch destination address is not known until execution of a register indirect branch, a register indirect subroutine call, or the like, the instruction conversion unit 303 executes a branch on the target CPU in the register simulator 35. From the contents of the register holding the destination address (referred to as address X) and the magnification N, the address in the simulation function call sequence to be branched is calculated as the start address of the simulation function call sequence 33 +
(N × X) is converted into a simulation function call that calls a simulation function including an instruction sequence that transfers control to that address. Below, an example of the register indirect branch instruction of 8086, an example of the simulation function call of the R3000 after the conversion, and an example of the simulation function of the R3000 called by this are shown.
【0059】 ○8086の命令 JMP [BX] /*2バイト命令*/ ○シミュレーション関数呼び出し li a0,BX /*BXはレジスタを表す定数*/ jal F_JMP_R /*シミュレーション関数の呼び出し*/ nop /*分岐遅延スロットを埋めるためのnop */ j v0 /*v0はF_JMP_R()のリターン値 */ nop nop nop nop ○シミュレーション関数 F_JMP_R(reg) int reg; { unsigned long addr; PC=Reg[reg]; addr=((Reg[CS]<<4)+PC)*16 +START_SDDRESS; /*16は定数倍Nの値,START_SDDRESSは変 換後のコードの先頭アドレス*/ return(addr) }Instruction of 8086 JMP [BX] / * 2 byte instruction * / Simulation function call lia0, BX / * BX is a constant representing a register * / jar F_JMP_R / * Call simulation function * / nop / * Branch Nop * / jv0 / * v0 for filling the delay slot is the return value of F_JMP_R () * / nop nop nop nop Simulation function F_JMP_R (reg) int reg; {unsigned long addr; PC = Regreg; = ((Reg [CS] << 4) + PC) * 16 + START_SDDRESS; / * 16 is the value of a constant multiple N, START_SDDRESS is the start address of the converted code * / return (addr)}
【0060】即ち、BXレジスタの保持している値をア
ドレスと認識してそのアドレスへ分岐する8086のレ
ジスタ間接分岐の場合、レジスタBXを表す定数を引数
としてシミュレーション関数F_JMP_Rを呼び出す
シミュレーション関数呼び出しを生成する。シミュレー
ション関数F_JMP_Rでは、 PC=Reg[reg]; により、8086上での分岐先のアドレスを保持してい
るレジスタの値(Reg[reg])をレジスタシミュ
レータ35から参照してレジスタシミュレータ35中の
PCの値を更新し、次いで、 addr=((Reg[CS]<<4)+PC)*16 +START_SDDRESS; を実行する。これは、8086で実行すべき命令のアド
レスは、セグメントレジスタ(ここではCS)とPCで
指定されるので、(Reg[CS]<<4)+PCによ
り8086上でのアドレスを算出し、これに定数16を
乗じたものにシミュレーション関数呼び出し列33の先
頭アドレスを加算することにより、分岐すべきホストC
PU32上のアドレスを求める。そして、 return(addr) により、この求めたアドレスをリターン値として返却す
る。このリターン値はR3000の場合、V0レジスタ
に格納されるので、シミュレーション関数呼び出しで
は、 j v0 を実行することにより、次にシミュレートすべき命令に
対応するシミュレーション関数呼び出し列33の部分へ
分岐する。That is, in the case of the register indirect branch of 8086 in which the value held in the BX register is recognized as an address and branch is made to the address, a simulation function call for calling the simulation function F_JMP_R with a constant representing the register BX as an argument is generated. I do. In the simulation function F_JMP_R, the value of the register (Reg [reg]) holding the address of the branch destination on the 8086 is referred to from the register simulator 35 by PC = Reg [reg]; And then execute addr = ((Reg [CS] << 4) + PC) * 16 + START_SDDRESS; Since the address of the instruction to be executed in the 8086 is specified by the segment register (here, CS) and the PC, the address on the 8086 is calculated by (Reg [CS] << 4) + PC. By adding the head address of the simulation function calling sequence 33 to the product of the constant 16 and the host C to be branched,
Find the address on PU32. Then, the obtained address is returned as a return value by return (addr). Since this return value is stored in the V0 register in the case of R3000, the simulation function call branches to the simulation function call sequence 33 corresponding to the instruction to be simulated next by executing j v0.
【0061】なお、命令変換部303は、実行前に分岐
先が確定している分岐命令コードの変換も行うが、本実
施例では、ターゲットCPUの命令コードのターゲット
CPU上でのアドレスに対応するシミュレーション関数
呼び出しのホストCPU32上でのアドレスは計算によ
って求まるので、図2に示したようなアドレス対応表1
03−1や変換結果一時記憶手段103−2は基本的に
は不要である。The instruction conversion unit 303 also converts a branch instruction code whose branch destination has been determined before execution. In this embodiment, the instruction conversion unit 303 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 32 is obtained by calculation, the address correspondence table 1 shown in FIG.
03-1 and the conversion result temporary storage means 103-2 are basically unnecessary.
【0062】さて、命令変換部303は、シミュレーシ
ョン関数呼び出しを生成すると、生成したシミュレーシ
ョン関数呼び出しを出力部304に伝達し、出力部30
4は、これを図3のメモリ31あるいは図示しない外部
記憶装置に順次格納する。When the instruction conversion unit 303 generates a simulation function call, the instruction conversion unit 303 transmits the generated simulation function call to the output unit 304, and outputs the simulation function call to the output unit 30.
4 sequentially stores them in the memory 31 of FIG. 3 or an external storage device (not shown).
【0063】CPUシミュレータ3は、変換手段30に
よってメモリ31上にシミュレーション関数呼び出し列
33が生成されると、シミュレーション関数呼び出し列
33がマシン語レベルで生成されているときは、ホスト
CPU32にメモリ31上のシミュレーション関数呼び
出し列33を実行させる。When the simulation function calling sequence 33 is generated on the memory 31 by the conversion means 30, the CPU simulator 3 transmits the simulation function calling sequence 33 to the host CPU 32 when the simulation function calling sequence 33 is generated at the machine language level. Is executed.
【0064】ホストCPU32は、先ずターゲットプロ
グラムの実行開始番地に対応するシミュレーション関数
呼び出しを実行する。従って、シミュレーション関数呼
び出し33−1をターゲットプログラムの実行開始番地
に対応するシミュレーション関数呼び出しとすると、ホ
ストCPU32は、先ずシミュレーション関数呼び出し
33−1を実行する。これにより、上述した例ではシミ
ュレーション関数34−1が呼び出されて実行され、レ
ジスタシミュレータ35中のレジスタの値を参照,更新
しながら命令コード4−1がシミュレートされる。The host CPU 32 first executes a simulation function call corresponding to the execution start address of the target program. Accordingly, if the simulation function call 33-1 is a simulation function call corresponding to the execution start address of the target program, the host CPU 32 first executes the simulation function call 33-1. Thus, in the above-described example, the simulation function 34-1 is called and executed, and the instruction code 4-1 is simulated while referring to and updating the value of the register in the register simulator 35.
【0065】ホストCPU32は、シミュレーション関
数34−1の実行が終了すると、次のシミュレーション
関数呼び出し33−2を実行する。これにより、上述し
た例ではシミュレーション関数34−mが呼び出されて
実行され、レジスタシミュレータ35中のレジスタの値
を参照,更新しながら命令コード4−2がシミュレート
される。When the execution of the simulation function 34-1 ends, the host CPU 32 executes the next simulation function call 33-2. Thus, in the above-described example, the simulation function 34-m is called and executed, and the instruction code 4-2 is simulated while referring to and updating the value of the register in the register simulator 35.
【0066】以下、上述の動作の繰り返しによりシミュ
レーション関数群34中の該当するシミュレーション関
数34−1〜34−mが呼び出されることにより、ター
ゲットプログラム4にかかるターゲットCPUの動作が
ホストCPU32上でシミュレートされる。Subsequently, the corresponding simulation functions 34-1 to 34-m in the simulation function group 34 are called by repetition of the above-described operation, whereby the operation of the target CPU according to the target program 4 is simulated on the host CPU 32. Is done.
【0067】なお、シミュレーション関数呼び出し列3
3がアセンブラ言語レベルで生成されているときは、C
PUシミュレータ3はこれをアセンブルしてマシン語レ
ベルのシミュレーション関数呼び出し列を生成し、これ
をホストCPU32上で実行することによりシミュレー
ションを実行する。また、変換手段30によって出力さ
れたシミュレーション関数呼び出し列33が外部記憶装
置に格納されている場合、CPUシミュレータ3はその
外部記憶装置からシミュレーション関数呼び出し列をメ
モリ31上に読み込んだ後に実行を開始する。The simulation function calling sequence 3
3 is generated at the assembler language level, C
The PU simulator 3 assembles this to generate a simulation function call sequence at a machine language level, and executes this on the host CPU 32 to execute a simulation. Further, when the simulation function calling sequence 33 output by the conversion means 30 is stored in the external storage device, the CPU simulator 3 starts executing after reading the simulation function calling sequence from the external storage device into the memory 31. .
【0068】図5は本発明の別の実施例のCPUシミュ
レータの機能ブロック図である。この実施例のCPUシ
ミュレータ5は、ターゲットプログラム6をシミュレー
ション関数呼び出し列53に変換すると共にアドレス変
換テーブル56を生成する変換手段50と、シミュレー
ション関数呼び出し列53,シミュレーション関数群5
4,レジスタシミュレータ55,アドレス変換テーブル
56およびデバッグ手段57を格納するメモリ51と、
シミュレーション関数呼び出し列53等を実行するホス
トCPU52とを含んでいる。FIG. 5 is a functional block diagram of a CPU simulator according to another embodiment of the present invention. The CPU simulator 5 of this embodiment converts a target program 6 into a simulation function calling sequence 53 and generates an address conversion table 56, a simulation function calling sequence 53, and a simulation function group 5.
4, a memory 51 for storing a register simulator 55, an address conversion table 56, and a debugging means 57;
And a host CPU 52 that executes a simulation function calling sequence 53 and the like.
【0069】ターゲットプログラム6は、ターゲットC
PU用に開発されたプログラムであり、ターゲットCP
Uのマシン語レベルの命令コード6−1〜6−nで構成
されている。ここで、先頭の命令コード6−1は、ター
ゲットCPU上ではアドレス0番地に位置し、次の命令
コード6−2はアドレス1番地に位置し、最後の命令コ
ード6−nはn番地に位置している。The target program 6 includes a target C
It is a program developed for PU and target CP
It is composed of U machine language level instruction codes 6-1 to 6-n. Here, the first instruction code 6-1 is located at address 0 on the target CPU, the next instruction code 6-2 is located at address 1 and the last instruction code 6-n is located at address n. doing.
【0070】シミュレーション関数呼び出し列53は、
変換手段50がターゲットプログラム6を処理して生成
したもので、ホストCPU52のアセンブラ言語レベル
またはマシン語レベルで表現されたシミュレーション関
数呼び出し53−1〜53−nで構成されている。ここ
で、先頭のシミュレーション関数呼び出し53−1は命
令コード6−1を変換したもの、次のシミュレーション
関数呼び出し53−2は命令コード6−2を変換したも
の、最後のシミュレーション関数呼び出し53−nは命
令コード6−nを変換したものであり、ホストCPU5
2のアドレス空間上ではメモリ51のアドレスA,B,
…,Nから始まる位置にそれぞれ格納されている。な
お、本実施例では図3の実施例と異なり、図1の基本構
成と同様に各シミュレーション関数呼び出し53−1〜
53−nは元の命令コードのバイト数のN倍といった制
限を受けず、可能な限り少ないコード量になるように生
成されている。The simulation function calling sequence 53 is
The conversion means 50 is generated by processing the target program 6 and includes simulation function calls 53-1 to 53-n expressed at the assembler language level or the machine language level of the host CPU 52. Here, the first simulation function call 53-1 is obtained by converting the instruction code 6-1, the next simulation function call 53-2 is obtained by converting the instruction code 6-2, and the last simulation function call 53-n is obtained by The instruction code 6-n is converted, and the host CPU 5
2, the addresses A, B,
.., N. In this embodiment, unlike the embodiment of FIG. 3, the basic structure of FIG.
Each simulation function calls in the same way as adult 53-1~
53-n is not restricted by N times the number of bytes of the original instruction code, and is generated so that the code amount is as small as possible.
【0071】アドレス変換テーブル56は、変換手段5
0がターゲットプログラム6を処理して生成したもの
で、例えば図6に示すように、ターゲットプログラム6
のマシン語レベルの各命令コード6−1,6−2,…,
6−nのターゲットCPU上のアドレス0,1,…,n
をインデックスとして、変換後のシミュレーション関数
呼び出し53−1,53−2,…,53−nのホストC
PU52のアドレス空間上のアドレスA,B,…,Nを
保持している。なお、後述するように、デバッグ時には
アドレス変換テーブル56にはデバッグ手段57を構成
する種々の関数のアドレスが格納される。The address conversion table 56 is stored in the
0 is generated by processing the target program 6. For example, as shown in FIG.
, 6-2,..., Machine code level instruction codes
6-n addresses 0, 1,..., N on the target CPU
Is used as an index, and the host C of the converted simulation function calls 53-1, 53-2,..., 53-n
The addresses A, B,..., N in the address space of the PU 52 are held. As will be described later, at the time of debugging, addresses of various functions constituting the debugging means 57 are stored in the address conversion table 56.
【0072】シミュレーション関数群54は、シミュレ
ーション関数54−1〜54−mの集合である。各シミ
ュレーション関数54−1〜54−mはターゲットCP
Uのマシン語レベルの各命令コードに1対1に対応して
おり、対応するターゲットCPUの命令コードをシミュ
レートする。シミュレーション関数54−1〜54−m
は例えばC言語で記述される。The simulation function group 54 is a set of simulation functions 54-1 to 54-m. Each simulation function 54-1 to 54-m is a target CP
The instruction codes correspond to the instruction codes at the machine language level of U on a one-to-one basis, and simulate the instruction codes of the corresponding target CPU. Simulation functions 54-1 to 54-m
Is described, for example, in the C language.
【0073】レジスタシミュレータ55は、ターゲット
CPU上のシミュレーション対象とするレジスタに1対
1に対応付けたレジスタの集まりであり、ホストCPU
52はこのレジスタシミュレータ55を参照,更新する
ことによりターゲットCPU上のレジスタをシミュレー
ションする。The register simulator 55 is a set of registers associated with the registers to be simulated on the target CPU in one-to-one correspondence.
52 simulates a register on the target CPU by referring to and updating this register simulator 55.
【0074】デバッグ手段57は、ターゲットプログラ
ム6のデバッグを支援する手段であり、ブレークポイン
ト設定関数57−1とブレークポイント処理関数57−
2と不正アドレス実行時処理関数57−3とを含んでい
る。The debugging means 57 supports debugging of the target program 6, and includes a breakpoint setting function 57-1 and a breakpoint processing function 57-
2 and an illegal address execution time processing function 57-3.
【0075】ブレークポイント設定関数57−1は、図
示しないキーボード等の入力手段からの指示によりホス
トCPU52で実行される関数であり、アドレス変換テ
ーブル56中の任意のインデックスに対応するアドレス
をブレークポイント処理関数57−2のアドレス Brk_
point に変更する処理を行う。The breakpoint setting function 57-1 is a function executed by the host CPU 52 in accordance with an instruction from an input means such as a keyboard (not shown), and performs a breakpoint processing on an address corresponding to an arbitrary index in the address conversion table 56. Address Brk_ of function 57-2
Perform processing to change to point.
【0076】ブレークポイント処理関数57−2は、ホ
ストCPU52で実行されることにより、ホストCPU
52を入力待ちにする関数である。利用者はその後に種
々のコマンドを入力することにより、メモリ51やレジ
スタの参照が可能になる。また処理の継続を指定する
と、ブレークポイント処理関数57−2から復帰し、処
理が継続する。The breakpoint processing function 57-2 is executed by the host CPU 52 to execute
52 is a function to wait for input. After that, the user can input various commands to refer to the memory 51 and the register. When the continuation of the process is designated, the process returns from the breakpoint processing function 57-2 and the process is continued.
【0077】不正アドレス実行時処理関数57−3は、
ホストCPU52から呼び出されて実行されることによ
り、図示しないCRT等の出力手段から不正なアドレス
が実行された旨およびそのアドレスを出力する等の処理
を行う。この不正アドレス実行時処理関数57−3のア
ドレスはAddr_err である。The illegal address execution time processing function 57-3 is
By being called and executed by the host CPU 52, processing such as the fact that an incorrect address has been executed from an output unit such as a CRT (not shown) and the output of the address are performed. The address of the illegal address execution processing function 57-3 is Addr_err.
【0078】図5の実施例において、CPUシミュレー
タ5は、ターゲットプログラム6にかかるターゲットC
PUの動作のシミュレーションを実行する場合、シミュ
レーションの実行に先立って変換手段50を起動する。In the embodiment shown in FIG. 5, the CPU simulator 5
When performing the simulation of the operation of the PU, the conversion unit 50 is activated prior to the execution of the simulation.
【0079】変換手段50は、例えば図7に示すよう
に、命令コード読み込み部501と命令解釈部502と
命令変換部503と出力部504,505とで構成され
ており、起動されると、先ず命令コード読み込み部50
1は図示しないメモリやファイル等に格納された図5の
ターゲットプログラム6をその先頭から順次1命令コー
ドずつ読み込んで命令解釈部502に伝達する。As shown in FIG. 7, for example, the conversion means 50 comprises an instruction code reading section 501, an instruction interpretation section 502, an instruction conversion section 503, and output sections 504 and 505. Instruction code reading unit 50
Reference numeral 1 sequentially reads the target program 6 shown in FIG.
【0080】命令解釈部502は、命令コード読み込み
部501から伝達された命令コードがどのような命令な
のかを解釈し、命令の種類,命令に使用されるレジス
タ,メモリアドレス,定数等を判別し、判別結果を命令
変換部503に伝達する。The instruction interpreting 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, a register used for the instruction, a memory address, a constant, and the like. , And transmits the determination result to the instruction conversion unit 503.
【0081】命令変換部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 of the host CPU 52 or the machine language level.
【0082】例えば、ターゲットCPUがインテル社の
16ビットプロセッサ8086であり、ホストCPU3
2がMIPS社の32ビットプロセッサR3000であ
る場合、命令変換部503は、8086の命令コード
を、R3000で実行可能なシミュレーション関数を呼
び出すシミュレーション関数呼び出しを生成することに
なる。For example, the target CPU is an Intel 16-bit processor 8086, and the host CPU 3
If 2 is a MIPS 32-bit processor R3000, the instruction conversion unit 503 generates a simulation function call that calls a simulation function that can execute the instruction code of 8086 in R3000.
【0083】以下に、8086の命令,R3000のシ
ミュレーション関数呼び出し,シミュレーション関数の
例を示す。なお、8086の命令とR3000のシミュ
レーション関数呼び出しとはアセンブラ表記で、R30
00のシミュレーション関数はC言語で示す。The following is an example of the instruction of 8086, the call of the simulation function of R3000, and the simulation function. Note that the instruction of 8086 and the simulation function call of R3000 are expressed in assembler notation, and R30
The simulation function of 00 is shown in C language.
【0084】 ○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*/ }Instruction of 8086 (example of normal instruction) MOV AX, 0x1000 / * 3-byte instruction * / Simulation function call lia0, AX / * AX is a constant representing a register * / lia1, 0x1000 jar F_MOV / * Call of simulation function * / nop / * nop to fill branch delay slot * / j v0 nop / * nop to fill branch delay slot * / ○ Simulation function F_MOV (reg, imm) int reg; short imm; PC PC + = 3; Reg [reg] = imm; / * Reg [] is a variable that holds register information * / return (AddrTbl [(Reg [CS] << 4) + PC]); / * AddrTbl [] Is the address conversion table 56 * /}
【0085】上記のシミュレーション関数における return(AddrTbl[(Reg[CS]<<
4)+PC]); は、8086で実行すべき命令のアドレス(Reg[C
S]<<4)+PCをインデックスとしてアドレス変換
テーブル56を参照してそのインデックスに対応するホ
ストCPU52上のアドレスを得てリターン値として返
却するもので、シミュレーション関数呼び出し側では、 j v0 を実行することにより、次にシミュレートすべき命令に
対応するシミュレーション関数呼び出し列53の部分へ
分岐する。このようにしたのは、後述するようにアドレ
ス変換テーブル56を利用したデバッグを可能にするた
めであるが、デバッグを考慮しない場合であっても、割
込み処理のシミュレーションを行う場合には必要であ
る。In the above simulation function, return (AddrTbl [(Reg [CS] <<<<
4) + PC]); is the address (Reg [C
S] << 4) Using the + PC as an index, refer to the address conversion table 56, obtain the address on the host CPU 52 corresponding to the index, and return it as a return value. The simulation function caller executes j v0 As a result, the process branches to the part of the simulation function call sequence 53 corresponding to the instruction to be simulated next. The reason for this is to enable debugging using the address conversion table 56 as described later. However, even when debugging is not taken into account, it is necessary to simulate interrupt processing. .
【0086】また命令変換部503は、変換元の命令コ
ードが、レジスタ間接分岐,レジスタ間接サブルーチン
呼び出し等実行時まで分岐先アドレスのわからない命令
コードの場合、シミュレーションの結果得られたターゲ
ットCPU上での分岐先アドレスとアドレス変換テーブ
ル56の内容とから分岐すべきシミュレーション関数呼
び出し列53中のアドレスを求め且つそのアドレスに制
御を移すような命令列を含むシミュレーション関数を呼
び出すシミュレーション関数呼び出しに変換する。以下
に、8086のレジスタ間接分岐命令の例と、その変換
後のR3000のシミュレーション関数呼び出しの例
と、これによって呼び出されるR3000のシミュレー
ション関数の例とを示す。If the instruction code of the conversion source is an instruction code whose branch destination address is not known until execution of a register indirect branch, a register indirect subroutine call, or the like, the instruction conversion unit 503 executes the simulation on the target CPU. Based on the branch destination address and the contents of the address conversion table 56, an address in the simulation function call sequence 53 to be branched is obtained, 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 the R3000 after the conversion, and an example of the simulation function of the R3000 called by this are shown.
【0087】 ○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*/ }Instruction of 8086 JMP [BX] / * 2 byte instruction * / ○ Simulation function call lia0, BX / * BX is a constant representing a register * / jar F_JMP_R / * Call of simulation function * / nop / * branch Nop * / jv0 / * v0 for filling the delay slot is the return value of F_JMP_R () * / nop / * nop * / for filling the branch delay slot Simulation function F_JMP_R (reg) int reg; {PC = Reg [Reg]; return (AddrTbl [(Reg [CS] << 4) + PC]); / * AddrTbl [] is an address conversion table 56 * / {
【0088】即ち、JMP [BX]の場合、レジス
タBXを表す定数を引数としてシミュレーション関数F
_JMP_Rを呼び出すシミュレーション関数呼び出し
を生成する。シミュレーション関数F_JMP_Rで
は、 PC=Reg[reg]; により、8086上での分岐先のアドレスを保持してい
るレジスタの値(Reg[reg])をレジスタシミュ
レータ55から参照してレジスタシミュレータ55中の
PCの値を更新し、次いで、 return(AddrTbl[(Reg[CS]<<
4)+PC]); を実行する。これは、8086で実行すべき命令のアド
レスは、セグメントレジスタ(ここではCS)とPCで
指定されるので、(Reg[CS]<<4)+PCによ
り8086上でのアドレスを算出し、これをインデック
スとしてアドレス変換テーブル56を参照し、得たアド
レスをリターン値として返却する。シミュレーション関
数呼び出し側では、 j v0 を実行することにより、次にシミュレートすべき命令に
対応するシミュレーション関数呼び出し列53の部分へ
分岐する。That is, in the case of JMP [BX], the simulation function F
Generate a simulation function call that calls _JMP_R. In the simulation function F_JMP_R, the value of the register (Reg [reg]) holding the address of the branch destination on the 8086 is referred to from the register simulator 55 by PC = Reg [reg]; , And then return (AddrTbl [(Reg [CS] <<
4) + PC]); Since the address of the instruction to be executed in the 8086 is specified by the segment register (here, CS) and the PC, the address on the 8086 is calculated by (Reg [CS] << 4) + PC, and The address conversion table 56 is referred to as an index, and the obtained address is returned as a return value. By executing j v0, the simulation function call side branches to the simulation function call sequence 53 corresponding to the instruction to be simulated next.
【0089】なお、命令変換部503は、実行前に分岐
先が確定している分岐命令コードの変換も行うが、本実
施例では、ターゲットCPUの命令コードのターゲット
CPU上でのアドレスに対応するシミュレーション関数
呼び出しのホストCPU上でのアドレスはアドレス変換
テーブル56によって求めることができるので、図2に
示したようなアドレス対応表103−1や変換結果一時
記憶手段103−2は基本的には不要である。以下に、
8086の分岐命令の例と、その変換後のR3000の
シミュレーション関数呼び出しの例と、これによって呼
び出されるR3000のシミュレーション関数の例とを
示す。Note that the instruction conversion unit 503 also converts a branch instruction code whose branch destination has been determined 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 from the address conversion table 56, the address correspondence table 103-1 and the conversion result temporary storage means 103-2 as shown in FIG. 2 are basically unnecessary. It is. less than,
An example of a branch instruction of 8086, an example of a simulation function call of R3000 after the conversion, and an example of a simulation function of R3000 called by this are shown.
【0090】 ○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*/ }Instruction of 8086 JMP 0x2000 / * 2-byte instruction * / O Simulation function call lia0,0x2000 jar F_JMP / * Call of simulation function * / nop / * nop * / jv0 / to fill 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 PC = addr; return (AddrTbl [(Reg [CS] < <4) + PC]); / * AddrTbl [] is an address conversion table 56 * / {
【0091】さて、命令変換部503は、シミュレーシ
ョン関数呼び出しを生成すると、生成したシミュレーシ
ョン関数呼び出しを出力部504に伝達し、出力部50
4は、これを図5のメモリ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 outputs the simulation function call.
4 sequentially stores them in the memory 51 of FIG. 5 or an external storage device (not shown).
【0092】また、命令変換部503は、ターゲットプ
ログラム6中の1命令の変換を行うごとに出力部505
を通じてメモリ51あるいは図示しない外部記憶装置に
アドレス変換テーブルの1エントリを出力する。これに
より、ターゲットプログラム6の全命令の変換が完了し
た時点で、ターゲットプログラム6のマシン語レベルの
各命令コード6−1,6−2,…,6−nのターゲット
CPU上のアドレス0,1,…,nをインデックスとし
て、変換後のシミュレーション関数呼び出し53−1,
53−2,…,53−nのホストCPU52のアドレス
空間上のアドレスA,B,…,Nを保持する図6の如き
アドレス変換テーブル56がメモリ51上あるいは図示
しない外部記憶装置に生成される。なお、外部記憶装置
にアドレス変換テーブル56が生成された場合、シミュ
レーションを開始する以前に外部記憶装置からメモリ5
1上へアドレス変換テーブル56を読み込む必要があ
る。The instruction conversion unit 503 outputs the output unit 505 every time one instruction in the target program 6 is converted.
And outputs one entry of the address conversion table to the memory 51 or an external storage device (not shown). Thus, when the conversion of all the instructions of the target program 6 is completed, the addresses 0, 1 on the target CPU of the instruction codes 6-1, 6-2,. ,..., N as indexes, the converted simulation function call 53-1,
., N in the address space of the host CPU 52 of 53-2,..., 53-n are generated in the memory 51 or an external storage device (not shown) as shown in FIG. . When the address conversion table 56 is generated in the external storage device, the memory 5 is stored in the external storage device before starting the simulation.
It is necessary to read the address conversion table 56 onto the address 1.
【0093】なお、デバッグを行うことが指示されてい
る場合、命令変換部503は、ターゲットプログラム6
の命令コード6−1〜6−nの先頭アドレス以外のアド
レスをインデックスとして、不正アドレス実行時処理関
数57−3のアドレスAddr_errをアドレス変換
テーブル56に設定する。例えば、1番地から2バイト
の命令コードが始まる場合、2番地は2バイトの命令コ
ードの途中であり、その番地から命令コードが始まらな
いので、2番地をインデックスとしてアドレスAddr
_errを設定する。When the instruction to debug is given, the instruction conversion unit 503 sends the instruction
The address Addr_err of the illegal address execution time processing function 57-3 is set in the address conversion table 56 by using an address other than the head address of the instruction codes 6-1 to 6-n as an index. For example, when a 2-byte instruction code starts from address 1, address 2 is in the middle of a 2-byte instruction code, and the instruction code does not start from that address.
_Err is set.
【0094】次に図5の実施例のシミュレーション実行
時の動作を説明する。先ずデバッグ機能を使用しないと
きの動作を説明する。Next, the operation of the embodiment of FIG. 5 when executing a simulation will be described. First, the operation when the debug function is not used will be described.
【0095】CPUシミュレータ5は、図示しない入力
手段からシミュレーションの実行開始の指示を受ける
と、シミュレーション関数呼び出し列53がマシン語レ
ベルで生成されているときは、ホストCPU52にメモ
リ51上のシミュレーション関数呼び出し列53を実行
させる。When receiving an instruction to start execution of a simulation from an input unit (not shown), the CPU simulator 5 calls the simulation function call sequence on the memory 51 to the host CPU 52 when the simulation function call sequence 53 is generated at the machine language level. The column 53 is executed.
【0096】ホストCPU52は、先ずシミュレーショ
ン関数呼び出し列53の先頭のシミュレーション関数呼
び出し53−1を実行する。これにより、上述した例で
はシミュレーション関数54−1が呼び出されて実行さ
れ、命令コード6−1がシミュレートされる。なお、こ
の関数では、概ね以下のような処理が行われる。 (a)レジスタシミュレータ55中のPCの値を更新す
る。 (b)引数で指定されたレジスタ,メモリの内容を参
照,更新し必要な処理を行う。 (c)必要ならば、PSWを変更する。 (d)分岐命令の場合、ホストCPU上での分岐先アド
レスを求める。 (e)リターン値を返却する。The host CPU 52 first executes the simulation function call 53-1 at the head of the simulation function call sequence 53. Thus, in the above-described example, the simulation function 54-1 is called and executed, and the instruction code 6-1 is simulated. In this function, the following processing is generally performed. (A) Update the value of PC in the register simulator 55. (B) Refer to and update the contents of the register and memory specified by the argument and perform necessary processing. (C) If necessary, change the PSW. (D) In the case of a branch instruction, a branch destination address on the host CPU is obtained. (E) Return the return value.
【0097】シミュレーション関数54−1の実行が終
了すると、本実施例では制御が呼び出し元のシミュレー
ション関数呼び出し53−1に一旦戻り、リターン値の
示すアドレスに分岐する。これにより、次にシミュレー
トすべき命令に対応するシミュレーション関数呼び出し
列53中に制御が移される。When the execution of the simulation function 54-1 is completed, in this embodiment, the control temporarily returns to the call of the simulation function call 53-1 of the caller, and branches to the address indicated by the return value. As a result, control is transferred to the simulation function calling sequence 53 corresponding to the instruction to be simulated next.
【0098】以下、上述の動作の繰り返しによりシミュ
レーション関数群54中の該当するシミュレーション関
数54−1〜54−mが呼び出されることにより、ター
ゲットプログラム6にかかるターゲットCPUの動作が
ホストCPU52上でシミュレートされる。Thereafter, the corresponding simulation functions 54-1 to 54-m in the simulation function group 54 are called by repetition of the above-described operation, whereby the operation of the target CPU according to the target program 6 is simulated on the host CPU 52. Is done.
【0099】次にデバッグ機能を使用したときの動作を
説明する。Next, the operation when the debug function is used will be described.
【0100】CPUシミュレータ5は、図示しない入力
手段からデバッグを伴うシミュレーションの実行開始の
指示を受けると、入力待ちとなる。When the CPU simulator 5 receives an instruction to start execution of a simulation involving debugging from an input means (not shown), it waits for an input.
【0101】利用者は、この状態において、図示しない
入力手段からデバッグ手段57のブレークポイント設定
関数57−1を起動することによりアドレス変換テーブ
ル56中の任意のインデックスに対応するアドレスにブ
レークポイント処理関数57−2のアドレスを設定する
ことができる。今、ターゲットプログラム6の1番地の
命令コード6−2にブレークポイントを設定したい場
合、設定したいアドレスを指定して起動すると、ブレー
クポイント設定関数57−1は、アドレス変換テーブル
56に図8に示すようにブレークポイント処理関数57
−2のアドレスBrk_pointを設定する。In this state, the user activates the break point setting function 57-1 of the debugging means 57 from the input means (not shown), so that the break point processing function is set to the address corresponding to an arbitrary index in the address conversion table 56. 57-2 can be set. If a breakpoint is to be set in the instruction code 6-2 at the address 1 of the target program 6, the address to be set is specified and the program is started. The breakpoint setting function 57-1 stores the address shown in FIG. Breakpoint processing function 57
-2 address Brk_point is set.
【0102】なお、デバッグを行うことが指示されてい
る場合、前述したように命令変換部503は、アドレス
変換テーブル56の生成時に、ターゲットプログラム6
の命令コード6−1〜6−nが存在しないアドレスをイ
ンデックスとして、不正アドレス実行時処理関数57−
3のアドレスAddr_errを、図8に例示するよう
にアドレス変換テーブル56に設定している。When the instruction to perform debugging is given, the instruction conversion unit 503 generates the address conversion table 56 as described above.
An illegal address execution time processing function 57-
The address Addr_err of No. 3 is set in the address conversion table 56 as illustrated in FIG.
【0103】さて、その後に図示しない入力手段から実
行の開始が指示されると、CPUシミュレータ5は、シ
ミュレーション関数呼び出し列53がマシン語レベルで
生成されているときは、ホストCPU52にメモリ51
上のシミュレーション関数呼び出し列53を実行させ、
ホストCPU52は、シミュレーション関数呼び出し列
53の先頭のシミュレーション関数呼び出し53−1か
ら実行を開始する。When the start of execution is instructed thereafter by an input means (not shown), the CPU simulator 5 sends the memory 51 to the host CPU 52 when the simulation function calling sequence 53 is generated at the machine language level.
The above simulation function calling sequence 53 is executed,
The host CPU 52 starts execution from the first simulation function call 53-1 of the simulation function call sequence 53.
【0104】そして、その後にターゲットプログラム6
の1番地が実行される場合、アドレス変換テーブル56
を参照すると、そこにはブレークポイント処理関数57
−2のアドレスが設定されているので、ホストCPU5
2はブレークポイント処理関数57−2を呼び出す。こ
れによりホストCPU52は利用者からの入力待ちとな
る。Then, the target program 6
Is executed, the address conversion table 56
, There is a breakpoint processing function 57
−2 is set, the host CPU 5
2 calls the breakpoint processing function 57-2. As a result, the host CPU 52 waits for an input from the user.
【0105】この状態で利用者が、デバッグに関する種
々のコマンドを入力すると、ホストCPU52はこれを
実行する。これにより、メモリ51やレジスタの内容を
図示しないCRT等に表示することが可能となる。そし
て、その後に処理の継続を指定すると、ホストCPU5
2はブレークポイント処理関数57−2から復帰し、処
理が継続される。In this state, when the user inputs various commands related to debugging, the host CPU 52 executes them. Thus, the contents of the memory 51 and the register can be displayed on a CRT (not shown). Then, when the continuation of the processing is designated, the host CPU 5
2 returns from the breakpoint processing function 57-2, and the processing is continued.
【0106】また、シミュレーションの実行において、
ターゲットプログラム6中で命令コードの先頭アドレス
でないアドレス、例えば2番地が実行される場合には、
アドレス変換テーブル56を参照すると、そこには不正
アドレス実行時処理関数57−3のアドレスが設定され
ている。従って、ホストCPU52は不正アドレス実行
時処理関数57−3を呼び出して実行するので、異常を
検出できる。In the execution of the simulation,
When an address other than the head address of the instruction code, for example, address 2 is executed in the target program 6,
Referring to the address conversion table 56, the address of the illegal address execution time processing function 57-3 is set therein. Therefore, since the host CPU 52 calls and executes the illegal address execution time processing function 57-3, an abnormality can be detected.
【0107】上記のブレークポイントと不正アドレス実
行検出は、アドレス変換テーブル56中の内容を変更す
るだけであるため、シミュレーション実行速度を低下さ
せることはない。The above-described breakpoint and illegal address execution detection only change the contents in the address conversion table 56, and do not lower the simulation execution speed.
【0108】以上本発明の実施例について説明したが、
本発明は以上の実施例にのみ限定されずその他各種の付
加変更が可能である。例えば、上記の各実施例では変換
手段をホストCPUとは別に備えるようにしたが、ホス
トCPUの機能で変換手段を実現するようにしても良
い。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 changes are possible. For example, in each of the above embodiments, the conversion means is provided separately from the host CPU, but the conversion means may be realized by the function of the host CPU.
【0109】[0109]
【発明の効果】以上説明したように、本発明によれば、
以下のような効果を得ることができる。As described above, according to the present invention,
The following effects can be obtained.
【0110】既提案CPUシミュレータのようにターゲ
ットCPUのマシン語レベルの各命令コードをホストC
PUの命令コードの組み合わせに変換するのではなく、
予め用意されたシミュレーション関数を呼び出すシミュ
レーション関数呼び出しに変換するため、変換後のコー
ド量を極力少なくすることができる。特に、1命令コー
ドがホストCPUの多数の命令コードに変換されるよう
な命令コードを多数含むターゲットプログラムの場合、
コード量の大幅な削減が可能となる。As in the case of the already proposed CPU simulator, each instruction code at the machine language level of the target CPU is
Instead of converting to a combination of PU instruction codes,
Since the conversion into a simulation function call that calls a simulation function prepared in advance, the amount of code after the conversion can be minimized. In particular, in the case of a target program including many instruction codes such that one instruction code is converted into many instruction codes of the host CPU,
The amount of code can be significantly reduced.
【0111】また、ターゲットプログラム中に同種の命
令コードが多数含まれており且つその命令コードがホス
トCPUの多数の命令コードに変換されるようなもので
ある場合、既提案CPUシミュレータでは、その各々の
命令コードがホストCPUの多数の命令コードに変換さ
れるため、変換後のコード量は膨大になるが、本発明で
は、上記同種の命令コードの各々に対する変換後のシミ
ュレーション関数呼び出し及びこれによって呼び出され
る共通のシミュレーション関数だけで済むので、シミュ
レーション関数のコード量を加味しても全体的なコード
量を削減することができる。If the target program contains many instruction codes of the same type and the instruction codes are converted into a large number of instruction codes of the host CPU, the proposed CPU simulator uses each of them. Is converted into a large number of instruction codes of the host CPU, the converted code amount becomes enormous. However, in the present invention, the converted simulation function call for each of the above-mentioned instruction codes of the same kind and the call by the simulation function call are executed. Since only a common simulation function is required, the overall code amount can be reduced even when the code amount of the simulation function is taken into account.
【0112】このようにコード量の削減が可能となるこ
とにより、例えば、主記憶容量の小さなホストCPUで
もシミュレーションが可能となり、またページングによ
る仮想記憶管理機構を使用したホストCPUではページ
アウト回数の減少が期待でき、更にキャッシュ機構を備
えたホストCPUではキャッシュヒット率の向上が期待
でき、既提案CPUシミュレータに比べてシミュレーシ
ョンの高速化が可能となる。Since the code amount can be reduced in this way, for example, a simulation can be performed even with a host CPU having a small main storage capacity, and the number of page-outs can be reduced with a host CPU using a virtual memory management mechanism by paging. In addition, the host CPU having the cache mechanism can be expected to improve the cache hit ratio, and the simulation can be sped up as compared with the proposed CPU simulator.
【0113】更に、本発明は既提案CPUシミュレータ
と同様にターゲットCPUの命令コードの解釈を前段階
でまとめて行っているので、ターゲットCPUの命令コ
ードをホストCPU上で実行時に1命令ずつ解釈する従
来のCPUシミュレータより高速なシミュレーションが
可能である。Further, in the present invention, the instruction codes of the target CPU are interpreted at the previous stage as in the case of the already proposed CPU simulator, so that the instruction codes of the target CPU are interpreted one by one when executed on the host CPU. Simulations faster than conventional CPU simulators are possible.
【0114】ターゲットプログラムのマシン語レベルの
各命令コードを、該命令コードのバイト数の定数倍のバ
イト数で構成されるシミュレーション関数呼び出しに変
換する構成では、実行前に分岐先のわかっている命令コ
ードの分岐先を計算で求めることができる利点があると
共に、レジスタのシミュレーションの結果得られたター
ゲットCPU上での分岐先アドレスと前記定数倍の倍率
とから分岐すべきシミュレーション関数呼び出し列中の
アドレスを計算によって求めることができるので、求め
たアドレスに制御を移す命令列を含ませた構成を採用す
ることにより、レジスタ間接分岐,レジスタ間接サブル
ーチン呼び出し等、実行時まで分岐先アドレスのわから
ないターゲットプログラムのマシン語レベルの命令コー
ドもシミュレーションすることができる。In a configuration in which each instruction code at the machine language level of the target program is converted into a simulation function call composed of a number of bytes that is a constant multiple of the number of bytes of the instruction code, an instruction whose branch destination is known before execution is executed. There is an advantage that the branch destination of the code can be obtained by calculation, and the address in the simulation function call sequence to be branched from the branch destination address on the target CPU obtained as a result of register simulation and the constant multiple magnification. Can be obtained by calculation. By adopting a configuration that includes an instruction sequence that transfers control to the obtained address, it is possible to obtain a target program whose branch destination address is not known until execution, such as register indirect branch or register indirect subroutine call. Simulate machine language level instruction codes It can be down.
【0115】ターゲットプログラムのマシン語レベルの
各命令コードのターゲットCPU上のアドレスと、該命
令コード変換後のシミュレーション関数のホストCPU
上のアドレスとの対応を示すアドレス変換テーブルを生
成する構成では、このアドレス変換テーブルを修正する
ことによりデバッグ等のための別の関数をシミュレーシ
ョン中に呼び出して実行することができる利点があると
共に、レジスタのシミュレーションの結果得られたター
ゲットCPU上での分岐先アドレスと前記アドレス変換
テーブルの内容とから分岐すべきシミュレーション関数
呼び出し列中のアドレスが求まるので、求めたアドレス
に制御を移す命令列を含ませた構成を採用することによ
り、シミュレーション関数呼び出しのバイト数を変換元
の命令コードのバイト数の定数倍に揃えることなく、レ
ジスタ間接分岐,レジスタ間接サブルーチン呼び出し
等、実行時まで分岐先アドレスのわからないターゲット
プログラムのマシン語レベルの命令コードのシミュレー
ションを、コード量の拡大を抑えて実現することができ
る。The address on the target CPU of each instruction code at the machine language level of the target program, and the host CPU of the simulation function after the conversion of the instruction code
The configuration for generating the address conversion table indicating the correspondence with the above address has an advantage that by modifying the address conversion table, another function for debugging or the like can be called and executed during the simulation, and Since the address in the simulation function call sequence to be branched is obtained from the branch destination address on the target CPU obtained as a result of the register simulation and the contents of the address conversion table, an instruction sequence for transferring control to the obtained address is included. By adopting this configuration, it is not possible to know the branch destination address until execution such as register indirect branch, register indirect subroutine call, etc. without aligning the number of bytes of the simulation function call to a constant multiple of the number of bytes of the conversion source instruction code. Target program machine The simulation instruction code level can be achieved while suppressing the expansion of code size.
【図1】本発明を適用したCPUシミュレータの基本構
成の機能ブロック図である。FIG. 1 shows the basic structure of a CPU simulator to which the present invention is applied.
It is a functional block diagram of the formation.
【図2】図1の変換手段10の構成例を示す機能ブロッ
ク図である。FIG. 2 is a functional block diagram showing a configuration example of a conversion unit 10 of FIG.
【図3】本発明を適用したCPUシミュレータの一実施
例の機能ブロック図である。FIG. 3 is a functional block diagram of a CPU simulator according to an embodiment of the present invention;
【図4】図3の変換手段30の構成例を示す機能ブロッ
ク図である。FIG. 4 is a functional block diagram showing a configuration example of a conversion unit 30 in FIG. 3;
【図5】本発明を適用したCPUシミュレータの別の実
施例の機能ブロック図である。FIG. 5 is a functional block diagram of another embodiment of a CPU simulator to which the present invention is applied.
【図6】図5のアドレス変換テーブル56の内容例を示
す図である。FIG. 6 is a diagram showing an example of contents of an address conversion table 56 of FIG. 5;
【図7】図5の変換手段50の構成例を示す機能ブロッ
ク図である。FIG. 7 is a functional block diagram showing a configuration example of a conversion unit 50 of FIG.
【図8】図5のアドレス変換テーブル56の別の内容例
を示す図である。FIG. 8 is a diagram showing another example of the contents of the address conversion table 56 of FIG. 5;
1,3,5…CPUシミュレータ 10,30,50…変換手段 11,31,51…メモリ 12,32,52…ホストCPU 13,33,53…シミュレーション関数呼び出し列 13−1〜13−n,33−1〜33−n,53−1〜
53−n…シミュレーション関数呼び出し 14,34,54…シミュレーション関数群 14−1〜14−m,34−1〜34−m,54−1〜
54−m…シミュレーション関数 2,4,6…ターゲットプログラム 2−1〜2−n,4−1〜4−n,6−1〜6−n…タ
ーゲットCPUのマシン語レベルの命令コード 35,55…レジスタシミュレータ 56…アドレス変換テーブル 57…デバッグ手段1, 3, 5 ... CPU simulator 10, 30, 50 ... conversion means 11, 31, 51 ... memory 12, 32, 52 ... host CPU 13, 33, 53 ... simulation function call sequence 13-1 to 13-n, 33 -1-33-n, 53-1
53-n: Call of simulation function 14, 34, 54: Simulation function group 14-1 to 14-m, 34-1 to 34-m, 54-1
54-m: Simulation function 2, 4, 6 ... Target program 2-1 to 2-n, 4-1 to 4-n, 6-1 to 6-n: Instruction code of machine language of target CPU 35, 55 ... Register simulator 56 ... Address conversion table 57 ... Debugging means
Claims (4)
CPUの動作をホストCPU上でシミュレートするCP
Uシミュレータにおいて、 前記ターゲットCPUのマシン語レベルの各命令コード
をシミュレートする、前記ホストCPUで実行可能なシ
ミュレーション関数を、前記ターゲットCPUのマシン
語レベルの命令コードの種類数分格納するシミュレーシ
ョン関数記憶手段と、 前記ターゲットCPU用に開発されたターゲットプログ
ラムのマシン語レベルの命令コードを解釈して、前記タ
ーゲットプログラムを、前記シミュレーション関数を呼
び出すシミュレーション関数呼び出しの集合であるシミ
ュレーション関数呼び出し列に変換する変換手段であっ
て 、前記ターゲットプログラムのマシン語レベルの各命
令コードを、該命令コードのバイト数の定数倍のバイト
数で構成されるシミュレーション関数呼び出しに変換す
る変換手段とを備え、 該変換手段により生成されたシミュレーション関数呼び
出し列を前記ホストCPUが実行することにより、前記
ターゲットプログラムにかかる前記ターゲットCPUの
動作のシミュレーションを行う構成を有する ことを特徴
とするCPUシミュレータ。1. A target to be simulated
CP simulating CPU operation on host CPU
In the U simulator, each instruction code at the machine language level of the target CPU
Simulates a system executable by the host CPU.
The simulation function is transferred to the machine of the target CPU.
Simulation for storing the number of word-level instruction codes
Means function storage means, and a target program developed for the target CPU.
Interprets the instruction code at the machine language level of
Target program is called by the simulation function.
Is a set of simulation function calls
Conversion means for converting the
Te, each instruction code of the machine language level of the target program, and a converting means for converting the constructed simulation function call in bytes of constant multiple of bytes of the instruction code, generated by the conversion means Simulation function call
The execution sequence is executed by the host CPU,
Of the target CPU according to the target program
A CPU simulator having a configuration for simulating an operation .
いて、 前記変換手段は、実行時まで分岐先アドレスのわからな
い前記ターゲットプログラムのマシン語レベルの命令コ
ードに対応して、レジスタのシミュレーションの結果得
られたターゲットCPU上での分岐先アドレスと前記定
数倍の倍率とから分岐すべきシミュレーション関数呼び
出し列中のアドレスを計算によって求めてリターン値と
して返却するシミュレーション関数を呼び出すと共に、
該呼び出したシミュレーション関数の終了時に前記リタ
ーン値の示すアドレスに分岐するシミュレーション関数
呼び出しを生成することを特徴とするCPUシミュレー
タ。2. The CPU simulator according to claim 1 , wherein the conversion unit obtains a result of register simulation corresponding to a machine language level instruction code of the target program whose branch destination address is not known until execution. A simulation function for calculating an address in a simulation function call sequence to be branched from the branch destination address on the target CPU and the magnification of the constant multiple, and calling a simulation function to return as a return value,
A CPU simulator for generating a simulation function call that branches to an address indicated by the return value when the called simulation function ends.
CPUの動作をホストCPU上でシミュレートするCP
Uシミュレータにおいて、 前記ターゲットCPUのマシン語レベルの各命令コード
をシミュレートする、 前記ホストCPUで実行可能なシ
ミュレーション関数を、前記ターゲットCPUのマシン
語レベルの命令コードの種類数分格納するシミュレーシ
ョン関数記憶手段と、 前記ターゲットCPU用に開発されたターゲットプログ
ラムのマシン語レベルの命令コードを解釈して、前記タ
ーゲットプログラムを、前記シミュレーション関数を呼
び出すシミュレーション関数呼び出しの集合であるシミ
ュレーション関数呼び出し列に変換する変換手段であっ
て、前記ターゲットプログラムのマシン語レベルの各命
令コードの前記ターゲットCPU上のアドレスと、該命
令コード変換後の前記シミュレーション関数呼び出しの
前記ホストCPU上のアドレスとの対応を示すアドレス
変換テーブルを生成し、 前記ターゲットプログラムのマ
シン語レベルの命令コードに対応して、レジスタのシミ
ュレーションの結果得られたターゲットCPU上での次
に実行すべきアドレスと前記アドレス変換テーブルの内
容とから次に実行すべきシミュレーション関数呼び出し
列中のアドレスを求めてリターン値として返却するシミ
ュレーション関数を呼び出すと共に、該呼び出したシミ
ュレーション関数の終了時に前記リターン値の示すアド
レスに分岐するシミュレーション関数呼び出しを生成す
る変換手段とを備え、 該変換手段により生成されたシミュレーション関数呼び
出し列を前記ホストCPUが実行することにより、前記
ターゲットプログラムにかかる前記ターゲットCPUの
動作のシミュレーションを行う構成を有する ことを特徴
とするCPUシミュレータ。3. A target to be simulated.
CP simulating CPU operation on host CPU
In the U simulator, each instruction code at the machine language level of the target CPU
Simulates a system executable by the host CPU.
The simulation function is transferred to the machine of the target CPU.
Simulation for storing the number of word-level instruction codes
Means function storage means, and a target program developed for the target CPU.
Interprets the instruction code at the machine language level of
Target program is called by the simulation function.
Is a set of simulation function calls
Conversion means for converting the
Each instruction at the machine language level of the target program
Instruction code address on the target CPU;
Of the simulation function call after the
An address indicating the correspondence with the address on the host CPU
A translation table is generated, and a next address to be executed on the target CPU obtained as a result of register simulation is obtained from the contents of the address translation table in accordance with the instruction code at the machine language level of the target program. converting means for seeking an address in the simulation function call sequence to be performed with calling the simulation function to return as a return value, to generate a simulation function calls to branch to the address indicated by the return value at the end of the simulation function that called the in And a simulation function call generated by the conversion means.
The execution sequence is executed by the host CPU,
Of the target CPU according to the target program
A CPU simulator having a configuration for simulating an operation .
いて、 前記アドレス変換テーブル中の、前記変換手段によって
設定されたターゲットCPU上のアドレスまたはそれ以
外のアドレスに対応して、前記シミュレーション関数呼
び出し以外の別の関数のアドレスを設定したことを特徴
とするCPUシミュレータ。4. The CPU simulator according to claim 3 , wherein, other than the call for the simulation function, the address conversion table corresponds to an address on the target CPU set by the conversion unit or another address. A CPU simulator, wherein an address of a function is set.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP5063446A JP2591418B2 (en) | 1993-02-26 | 1993-02-26 | CPU simulator |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| JP5063446A JP2591418B2 (en) | 1993-02-26 | 1993-02-26 | CPU simulator |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| JPH06250874A JPH06250874A (en) | 1994-09-09 |
| JP2591418B2 true JP2591418B2 (en) | 1997-03-19 |
Family
ID=13229488
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| JP5063446A Expired - Lifetime JP2591418B2 (en) | 1993-02-26 | 1993-02-26 | CPU simulator |
Country Status (1)
| Country | Link |
|---|---|
| JP (1) | JP2591418B2 (en) |
Families Citing this family (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JP2817786B2 (en) * | 1996-07-15 | 1998-10-30 | 日本電気株式会社 | Simulation apparatus and simulation method |
| JP4563669B2 (en) * | 2003-11-25 | 2010-10-13 | 三菱電機株式会社 | Instruction simulator |
| KR20050112890A (en) | 2004-05-28 | 2005-12-01 | 삼성전자주식회사 | Instruction decoding method in an architenctural simulator |
Family Cites Families (2)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| JPH02250122A (en) * | 1988-10-25 | 1990-10-05 | Nec Corp | Cpu simulator |
| JPH04310131A (en) * | 1991-04-09 | 1992-11-02 | Shikoku Nippon Denki Software Kk | Program method |
-
1993
- 1993-02-26 JP JP5063446A patent/JP2591418B2/en not_active Expired - Lifetime
Also Published As
| Publication number | Publication date |
|---|---|
| JPH06250874A (en) | 1994-09-09 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| US8463589B2 (en) | Modifying a virtual processor model for hardware/software simulation | |
| US5394544A (en) | Software system debugger with distinct interrupt vector maps for debugging and application programs | |
| JPH0628036B2 (en) | Simulation method | |
| EP0428560A4 (en) | Machine process for translating programs in binary machine language into another binary machine language | |
| CA2082068A1 (en) | System and method for automatically interfacing call conventions between two dissimilar program units | |
| JPH06348530A (en) | Portable method and apparatus for executing development, verification and test of computer system | |
| JP2591418B2 (en) | CPU simulator | |
| CN111324948A (en) | Simulation method and simulation system | |
| EP0731410B1 (en) | Method and processing for computer code processing in a code translator | |
| JP2788839B2 (en) | CPU simulator | |
| JPH0683615A (en) | Computer for executing instruction set emulation | |
| JPH0668724B2 (en) | Simulation method | |
| GB2366426A (en) | Multi-processor system with registers having a common address map | |
| JP2000259445A (en) | Software / hardware co-simulation method | |
| JPH06202903A (en) | Cpu simulation and cpu simulator | |
| Popovici et al. | Efficient software development platforms for multimedia applications at different abstraction levels | |
| JP2004013227A (en) | Simulation device and simulation model generation program | |
| Larsson et al. | Simgen: Development of efficient instruction set simulators | |
| JPH09171467A (en) | Emulation device and method therefor | |
| JP2637770B2 (en) | Microcomputer | |
| JPH06168140A (en) | Program converter | |
| Goessling et al. | ISPMET: a study in automatic emulator generation | |
| Haur et al. | Formal Model of the Lipsi Processor: Definition and Use of its Timing Behavior | |
| JPS6318444A (en) | System for developing software development supporting system | |
| JPH0745787Y2 (en) | Disassemble processor |