JPH05181703A - Data processor - Google Patents

Data processor

Info

Publication number
JPH05181703A
JPH05181703A JP4000666A JP66692A JPH05181703A JP H05181703 A JPH05181703 A JP H05181703A JP 4000666 A JP4000666 A JP 4000666A JP 66692 A JP66692 A JP 66692A JP H05181703 A JPH05181703 A JP H05181703A
Authority
JP
Japan
Prior art keywords
stack
value
subroutine
data
jsr
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.)
Pending
Application number
JP4000666A
Other languages
Japanese (ja)
Inventor
Hiromi Okazaki
弘美 岡崎
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.)
Mitsubishi Electric Corp
Original Assignee
Mitsubishi Electric 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 Mitsubishi Electric Corp filed Critical Mitsubishi Electric Corp
Priority to JP4000666A priority Critical patent/JPH05181703A/en
Publication of JPH05181703A publication Critical patent/JPH05181703A/en
Pending legal-status Critical Current

Links

Landscapes

  • Executing Machine-Instructions (AREA)
  • Debugging And Monitoring (AREA)

Abstract

PURPOSE:To protect the PC value of a preceding routine saved to a stack and a stack pointer value obtained after calling a subroutine. CONSTITUTION:In case of writing data in an area specified by the 1st register for saving a PC value to a PC stack instead of a normal stack and storing the initial value of PC stack pointer (PCSP) and the 2nd register for storing the value of the PCSP obtained after executing a subroutine instruction, an error is generated to interrupt processing. Consequently the generation of a change in a program flow due to the reading of an incorrect PC value or runaway can be prevented by protecting the PC value of a preceding routine from careless overwriting and distinguishing a stack for saving the PC value from a normal stack and debugging can easily be executed because of the protection of the PC value of the preceding routine.

Description

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

【0001】[0001]

【産業上の利用分野】この発明はデバッグサポート機能
とスタックポインタとを有するデータ処理装置に関する
ものである。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a data processing device having a debug support function and a stack pointer.

【0002】[0002]

【従来の技術】通常メモリからデータを読み出したり、
メモリにデータを書き込んだりする場合、読み書きにか
かわるメモリのアドレスを指定してデータの転送を行な
う方法が一般的であるが、アドレスの指定方法が通常の
場合とは異なるスタックと呼ばれるメモリとの間でデー
タの転送を行なうこともある。スタックとは先にいれた
データが後から出て来るような構造を持つデータの入れ
物である。スタックにデータを入れることをプッシュと
呼び、スタックからデータを出すことをポップと呼ぶ。
データをプッシュあるいはポップするアドレスは、スタ
ックポインタ(以下SPとする)で指定する。SPの値
はプッシュ、ポップ操作につれて変化し、常に最も新し
いスタック操作が行なわれたデータのアドレスを指して
いるので、後にプッシュされたデータから先にポップさ
れる。
2. Description of the Related Art Reading data from a normal memory,
When writing data to memory, it is common to specify the address of the memory involved in reading and writing and transfer the data, but the method of specifying the address is different from the usual case Data may be transferred in. A stack is a container for data that has a structure in which the previously put data comes out later. Putting data on the stack is called push, and putting data on the stack is called pop.
An address for pushing or popping data is designated by a stack pointer (hereinafter referred to as SP). The value of SP changes with push and pop operations and always points to the address of the data for which the newest stack operation has been performed, so the data pushed later is popped first.

【0003】従来よりデータ処理装置の中には、ジャン
プサブルーチン命令(以下JSRとする)でサブルーチ
ンを呼び出すときに、処理を中断するルーチンのプログ
ラムカウンタ(以下PCとする)値を保存するための記
憶装置としてスタックを利用しているものもある。この
ようなデータ処理装置において、プログラム中で[JS
R(ジャンプ先実効アドレス)]を実行すると、JSR
の次の命令の先頭アドレスを復帰後PC値としてスタッ
クにプッシュし、ジャンプ先実効アドレスを新PC値と
してPCにセットする。その後PCの内容を先頭アドレ
スとする命令をメモリから取り込んでサブルーチンの処
理に移る。このときSPの値はスタックにプッシュした
前ルーチンの復帰後PC値を格納したスタックのアドレ
スを指している。またサブルーチンの最後でリターンサ
ブルーチン命令(以下RTSとする)を実行すると、S
Pの内容の指すスタックから、退避していた復帰後PC
値をポップしてPCにセットし、前ルーチンのJSRの
次命令から処理を再開する。このときSPの値はJSR
を実行する前の値にもどっている。
Conventionally, a data processing device has a memory for storing a value of a program counter (hereinafter referred to as PC) of a routine for interrupting processing when a subroutine is called by a jump subroutine instruction (hereinafter referred to as JSR). Some use stacks as devices. In such a data processing device, [JS
R (jump destination effective address)]
After the return, the start address of the instruction is pushed to the stack as the PC value after restoration, and the jump destination effective address is set to the PC as the new PC value. After that, the instruction having the contents of the PC as the start address is fetched from the memory and the processing of the subroutine is started. At this time, the value of SP indicates the address of the stack that stores the PC value after the return of the previous routine pushed on the stack. If a return subroutine instruction (hereinafter referred to as RTS) is executed at the end of the subroutine, S
PC after recovery that was saved from the stack indicated by P
The value is popped and set in the PC, and the process is restarted from the instruction next to the JSR of the previous routine. At this time, the value of SP is JSR
It returns to the value before executing.

【0004】図5は従来のデータ処理装置においてメイ
ンプログラムの途中でJSRを実行してサブルーチン1
を呼び出したときの処理の流れとJSR実行前後のスタ
ックの状態について示したものである。図5でメインプ
ログラムは命令A0、B0、JSR、およびC0からな
り、サブルーチン1は命令A1、B1およびRTSから
なる。命令A0が格納されているメモリの先頭アドレス
をPC(A0)とし、同様に命令B0、JSR、C0、
A1、B1、RTSが格納されているメモリの先頭アド
レスをそれぞれPC(B0)、PC(JSR)、PC
(C0)、PC(A1)、PC(B1)、PC(RT
S)とする。JSRのジャンプ先実効アドレスはサブル
ーチン1の先頭命令A1が格納されているメモリの先頭
アドレスPC(A1)であるとする。JSRが実行され
る前のSPの値をSP(0)、JSRが実行された後の
SPの値をSP(1)とする。以下図3を用いてJSR
の動作を詳しく説明する。
FIG. 5 is a subroutine 1 in which the JSR is executed in the middle of the main program in the conventional data processing apparatus.
It shows the flow of processing when invoking and the state of the stack before and after the execution of JSR. In FIG. 5, the main program consists of instructions A0, B0, JSR, and C0, and subroutine 1 consists of instructions A1, B1, and RTS. The start address of the memory in which the instruction A0 is stored is PC (A0), and the instructions B0, JSR, C0,
The head addresses of the memory storing A1, B1, and RTS are PC (B0), PC (JSR), and PC, respectively.
(C0), PC (A1), PC (B1), PC (RT
S). The jump destination effective address of JSR is assumed to be the start address PC (A1) of the memory in which the start instruction A1 of subroutine 1 is stored. The value of SP before JSR is executed is SP (0), and the value of SP after JSR is executed is SP (1). The JSR will be described below with reference to FIG.
The operation of will be described in detail.

【0005】メインプログラム実行中に[JSR PC
(A1)]が読み込まれると、SPの値をSP(0)か
らSP(1)に変化させ、メインプログラムのJSRの
次命令C0の先頭アドレスPC(C0)を復帰後PC値
としてスタックにプッシュする。次にPCにJSRで指
定されたジャンプ先実効アドレスPC(A1)をセット
し、サブルーチン1の処理に移る。PC(A1)を先頭
アドレスとする命令A1から順次命令を読み込んで実行
し、サブルーチン1の最後で[RTS]が読み込まれる
と、スタックからSPの値SP(1)を先頭アドレスと
して退避していた復帰後PC値のPC(C0)をポップ
し、PCにセットしてメインプログラムの処理に戻る。
SPの値はSP(0)にもどっている。
During execution of the main program, [JSR PC
(A1)] is read, the value of SP is changed from SP (0) to SP (1) and the start address PC (C0) of the next instruction C0 of the main program JSR is pushed onto the stack as the PC value after restoration. To do. Next, the jump destination effective address PC (A1) designated by JSR is set in the PC, and the process of the subroutine 1 is started. When the instruction A1 having PC (A1) as the start address is sequentially read and executed and [RTS] is read at the end of subroutine 1, the value SP (1) of SP is saved as the start address from the stack. After returning, the PC value PC (C0) is popped, set in the PC, and the process returns to the main program.
The value of SP has returned to SP (0).

【0006】また図6は従来のデータ処理装置において
n回のサブルーチンジャンプを連続して行ったときの処
理の流れとJSR前のスタックの状態およびn回目のJ
SR実行後のスタックの状態について示したものであ
る。メインプログラムは命令A0、・・・、JSR、命
令C0、・・・からなり、サブルーチン1は命令A1、
・・・、JSR、命令C1、・・・、RTSからなる。
同様にサブルーチンjは命令Aj、・・・、JSR、命
令Cj、・・・、RTSからなる。命令A0、命令B
0、JSR、C0、はそれぞれPC(A0)、PC(B
0)、PC(JS0)、PC(C0)を先頭アドレスと
するメモリに格納されている。メインプログラムのJS
Rのジャンプ先実効アドレスはサブルーチン1の先頭命
令A1が格納されているメモリのアドレスPC(A1)
であるとする。同様にサブルーチンjの命令Aj、B
j、JSR、Cj、RTSはそれぞれPC(Aj)、P
C(Bj)、PC(JSj)、PC(Cj)、PC(R
Tj)を先頭アドレスとするメモリに格納されており、
サブルーチンj中のJSRのジャンプ先実効アドレスは
サブルーチン(j+1)の先頭命令A(j+1)が格納
されているメモリのアドレスPC(A(j+1))であ
るとする。1回目のJSRが実行される前のSPの値を
SP(0)、n回目のJSRが実行された後のSPの値
をSP(n)とする。以下図4を用いて詳しく説明を行
なう。
Further, FIG. 6 shows the flow of processing when n times of subroutine jumps are continuously performed in the conventional data processing apparatus, the state of the stack before JSR, and the nth J.
It shows the state of the stack after SR execution. The main program consists of instructions A0, ..., JSR, instructions C0 ,.
..., JSR, command C1, ..., RTS.
Similarly, the subroutine j is composed of instructions Aj, ..., JSR, instructions Cj ,. Instruction A0, instruction B
0, JSR, C0 are PC (A0) and PC (B
0), PC (JS0), and PC (C0) as the start addresses. Main program JS
The jump destination effective address of R is the address PC (A1) of the memory storing the first instruction A1 of subroutine 1.
Suppose Similarly, the instructions Aj and B of the subroutine j
j, JSR, Cj, and RTS are PC (Aj) and P, respectively.
C (Bj), PC (JSj), PC (Cj), PC (R
Tj) is stored in the memory having the start address as
The jump destination effective address of the JSR in the subroutine j is assumed to be the address PC (A (j + 1)) of the memory in which the head instruction A (j + 1) of the subroutine (j + 1) is stored. The SP value before the first JSR is executed is SP (0), and the SP value after the nth JSR is executed is SP (n). A detailed description will be given below with reference to FIG.

【0007】メインプログラム実行中に[JSR PC
(A1)]が読み込まれると、SPの値をSP(0)か
らSP(1)に変化させ、メインプログラムのJSRの
次命令C0の先頭アドレスPC(C0)を復帰後PC値
としてスタックにプッシュする。次に、PCにJSRで
指定されたジャンプ先実効アドレスPC(A1)をセッ
トし、サブルーチン1の処理に移る。PC(A1)を先
頭アドレスとする命令A1から順次命令を読み込んで実
行し、サブルーチン1の途中で[JSR PC(A
2)]が読み込まれると、SPの値をSP(1)からS
P(2)に変化させ、サブルーチン1のJSRの次命令
C1の先頭アドレスPC(C1)を復帰後PC値として
スタックにプッシュする。同様にn回のサブルーチンジ
ャンプを実行し、サブルーチンnの処理に移ったときス
タックにはn個のデータがプッシュされておりSPの値
はSP(n)になっている。サブルーチンnの最後で
[RTS]が読み込まれると、スタックからSPの値S
P(n)を先頭アドレスとする退避していたサブルーチ
ン(n−1)への復帰後PC値のPC(C(n−1))
をポップし、PCにセットしてサブルーチン(n−1)
の処理に戻る。SPの値はSP(n−1)にもどってい
る。同様にn回のRTS命令によりデータをポップして
PCにセットしながら処理を続けるとメインプログラム
の処理に戻ることができる。
During execution of the main program, [JSR PC
(A1)] is read, the value of SP is changed from SP (0) to SP (1) and the start address PC (C0) of the next instruction C0 of the main program JSR is pushed onto the stack as the PC value after restoration. To do. Next, the jump destination effective address PC (A1) designated by JSR is set in the PC, and the processing of the subroutine 1 is started. Instructions are sequentially read from the instruction A1 having PC (A1) as the start address and executed, and [JSR PC (A
2)] is read, the SP value is changed from SP (1) to S
It is changed to P (2), and the start address PC (C1) of the next instruction C1 of the JSR of the subroutine 1 is pushed onto the stack as the PC value after restoration. Similarly, when the subroutine jump is executed n times and the process of the subroutine n is started, n pieces of data are pushed onto the stack and the value of SP is SP (n). When [RTS] is read at the end of subroutine n, the value S of SP from the stack
PC (C (n-1)) of the PC value after returning to the saved subroutine (n-1) with P (n) as the start address
Pops, sets it on the PC, and makes a subroutine (n-1)
Return to processing. The value of SP has returned to SP (n-1). Similarly, by continuing the processing while popping the data by n times of RTS commands and setting it in the PC, it is possible to return to the processing of the main program.

【0008】また従来のデータ処理装置の中にも高級言
語用のスタックフレームの形成とレジスタの退避処理を
行なう命令としてスタックフレーム生成命令(以下EN
TERとする)、およびレジスタの復帰とスタックフレ
ーム開放、PC値の復帰処理を行なう命令(以下EXI
TDとする)を備えているものがある。
In the conventional data processing device, a stack frame generation instruction (hereinafter referred to as EN) is also used as an instruction for forming a stack frame for a high-level language and saving a register.
TER), and instructions to restore registers, release stack frames, and restore PC values (hereinafter referred to as EXI).
Some of them have TD).

【0009】図7はメインプログラムの途中でJSRに
よりサブルーチン1を呼び出した後ENTERを実行す
るときの処理の流れと、ENTERを実行する前のスタ
ックの状態、およびENTERを実行した後のスタック
の状態について説明したものである。図7でメインプロ
グラムは命令A0、B0、JSR、およびC0からな
り、サブルーチン1はENTER、・・・、EXITD
からなる。命令A0が格納されているメモリの先頭アド
レスをPC(A0)、同様に命令B0、JSR、C0、
ENTER、EXITDが格納されているメモリの先頭
アドレスをそれぞれPC(B0)、PC(JSR)、P
C(C0)、PC(EN)、PC(EX)とする。JS
Rのジャンプ先実効アドレスはサブルーチン1の先頭命
令ENTERが格納されているメモリの先頭アドレスP
C(EN)であるとする。JSRが実行される前のS
P、FPの値をそれぞれSP(0)、FP(0)、JS
Rが実行された後のSPの値をSP(1)、ENTER
が実行された後のSP、FPの値をそれぞれSP
(3)、SP(2)とする。以下図7を用いて詳しく説
明を行なう。
FIG. 7 shows the flow of processing when ENTER is executed after calling subroutine 1 by JSR in the middle of the main program, the state of the stack before executing ENTER, and the state of the stack after executing ENTER. Is explained. In FIG. 7, the main program consists of instructions A0, B0, JSR, and C0, and the subroutine 1 is ENTER, ..., EXITD.
Consists of. The start address of the memory in which the instruction A0 is stored is PC (A0), and similarly the instructions B0, JSR, C0,
The start address of the memory where ENTER and EXIT are stored is PC (B0), PC (JSR), P
Let C (C0), PC (EN), and PC (EX). JS
The jump destination effective address of R is the start address P of the memory in which the start instruction ENTER of subroutine 1 is stored.
It is assumed that it is C (EN). S before JSR is executed
The values of P and FP are SP (0), FP (0), and JS, respectively.
The value of SP after R is executed is SP (1), ENTER
The SP and FP values after executing
(3) and SP (2). A detailed description will be given below with reference to FIG. 7.

【0010】メインプログラムの途中で[JSR PC
(EN)]が読み込まれると、SPの値をSP(0)か
らSP(1)に変化させ、メインプログラムのJSRの
次命令C0の先頭アドレスPC(C0)を復帰後PC値
としてスタックにプッシュする。その後PCにJSRで
指定されたジャンプ先実効アドレスPC(EN)をセッ
トし、サブルーチン1の処理に移る。PC(EN)を先
頭アドレスとする命令ENTERを読み込んで実行する
と、まずENTER実行前のFPの値FP(0)をスタ
ックにプッシュし、FPにはSPの値SP(2)を新F
P値として格納する。その後スタックにローカル変数領
域を確保してから汎用レジスタ群をプッシュする。EN
TERの全てのスタックプッシュが終わったときSPの
値はSP(3)となっている。ENTER処理後サブル
ーチン1の処理を実行し、サブルーチン1の最後で[E
XITD]が読み込まれると、スタックからSPの値S
P(3)を先頭アドレスとしてまず汎用レジスタ群の値
をポップし、FPの値SP(2)をSPに格納してロー
カル変数領域を開放し、SPの示すスタックからFP値
としてFP(0)、復帰後PC値としてPC(C0)を
ポップしてそれぞれFP、PCにセットしメインプログ
ラムの処理に戻る。SPの値はSP(0)にもどってい
る。
[JSR PC
(EN)] is read, the value of SP is changed from SP (0) to SP (1), and the start address PC (C0) of the next instruction C0 of the main program JSR is pushed onto the stack as the PC value after restoration. To do. After that, the jump destination effective address PC (EN) designated by JSR is set in the PC, and the process of the subroutine 1 is started. When the instruction ENTER with PC (EN) as the start address is read and executed, the value FP (0) of FP before the execution of ENTER is pushed onto the stack, and the value SP (2) of SP is added to FP as the new F.
Store as P value. After that, the local variable area is secured on the stack and then the general-purpose register group is pushed. EN
The value of SP is SP (3) when all the stack pushes of the TER are completed. After the ENTER processing, the processing of subroutine 1 is executed, and at the end of subroutine 1, [E
XITD] is read, the SP value S from the stack
First, the value of the general-purpose register group is popped with P (3) as the start address, the FP value SP (2) is stored in SP to open the local variable area, and FP (0) is set as the FP value from the stack indicated by SP. , After the return, PC (C0) is popped as the PC value and set in FP and PC, respectively, and the process returns to the main program. The value of SP has returned to SP (0).

【0011】[0011]

【発明が解決しようとする課題】通常上記のようなスタ
ックはメモリの一部に置かれるため、上記のようにサブ
ルーチンジャンプが行われたときに前ルーチンの次命令
の先頭アドレスををスタックに退避する方法では、サブ
ルーチン実行中にPC値を退避してある場所へ不用意に
データを書き込んでしまったり、プッシュ操作やポップ
操作を行なってJSR後のSPと値が変わったままRT
Sを実行すると、サブルーチンを呼び出した前ルーチン
の復帰後PC値をポップすることができず、誤ったデー
タをPCにセットしてプログラムの流れが変わったり、
暴走したりして、プログラムそのものを傷つけたり、デ
ータを破壊してしまい、デバッグも困難になるという問
題点があった。
Since the stack as described above is usually placed in a part of the memory, the start address of the next instruction of the previous routine is saved in the stack when the subroutine jump is performed as described above. In this method, the PC value is accidentally written to the location where the PC value is saved during the execution of the subroutine, or a push operation or a pop operation is performed to change the RT value while the value is different from the SP after JSR.
If S is executed, the PC value cannot be popped after returning from the previous routine that called the subroutine, and incorrect data will be set in the PC, and the flow of the program will change.
There was a problem that the program itself would be damaged or data would be destroyed due to a runaway, making debugging difficult.

【0012】また、サブルーチン実行中にFPへ不用意
にデータを書き込んでしまい、FPの値が変わったまま
ENTERを実行すると、誤ったSP値を読み込むこと
になるので前ルーチンでのFP値を復帰することができ
なくなるという問題点があった。
If data is carelessly written to the FP during execution of the subroutine and ENTER is executed with the FP value changed, an incorrect SP value will be read, so the FP value in the previous routine is restored. There was a problem that it could not be done.

【0013】さらに従来例のようにスタックフレームを
形成した後で、サブルーチン実行中にプッシュ操作やポ
ップ操作を行なってENTER後のSPと値が変わった
ままEXITを実行すると、誤ったレジスタ値をポップ
してしまい、正しい結果が得られないという問題点もあ
った。
Further, if a push operation or a pop operation is performed during execution of a subroutine after forming a stack frame as in the conventional example and EXIT is executed with the value changed from SP after ENTER, an incorrect register value is popped. There was also a problem that the correct result could not be obtained.

【0014】この発明はかかる問題点を解決するために
なされたもので、スタックに退避した前ルーチンのPC
値とFP値等のデータが保護でき、PC値とFP値を格
納しているスタックのスタックポインタ値およびスタッ
クフレーム形成直後の通常スタックのSP値の正常性が
チェックできるデータ処理装置を得ることを目的とす
る。
The present invention has been made to solve the above problems, and the PC of the previous routine saved in the stack
To obtain a data processing device capable of protecting data such as a value and an FP value and checking the normality of a stack pointer value of a stack storing a PC value and an FP value and an SP value of a normal stack immediately after forming a stack frame. To aim.

【0015】[0015]

【課題を解決するための手段】第1の発明に係るデータ
処理装置は以下の要素を有するものである。 (a)所定の種類のデータを記憶する第1のスタック、
(b)上記第1のスタックに記憶されるデータ以外のデ
ータを記憶する第2のスタック、(c)データをスタッ
クに記憶する場合、そのデータの種類により上記第1と
第2のスタックのいずれかを選択する選択手段。
A data processing apparatus according to the first invention has the following elements. (A) a first stack for storing a predetermined type of data,
(B) a second stack that stores data other than the data stored in the first stack; (c) when storing data in the stack, whichever of the first and second stacks is used depending on the type of the data. Selection means for selecting or.

【0016】第2の発明に係るデータ処理装置は以下の
要素を有するものである。 (a)所定のデータを記憶するスタック、(b)上記ス
タックの使用されている領域への書き込みを禁止する禁
止手段。
A data processing apparatus according to the second invention has the following elements. (A) A stack that stores predetermined data, and (b) a prohibition unit that prohibits writing to a used area of the stack.

【0017】第3の発明に係るデータ処理装置は以下の
要素を有するものである。 (a)所定のデータを記憶するスタック、(b)上記ス
タックの先頭を示すスタックポインタ、(c)上記スタ
ックポインタの値を保持する保持手段、(d)上記スタ
ックポインタの値と保持手段の値を比較してスタックポ
インタの破壊を検査する検査手段。
A data processing apparatus according to the third invention has the following elements. (A) Stack for storing predetermined data, (b) Stack pointer indicating the top of the stack, (c) Holding means for holding the value of the stack pointer, (d) Value of the stack pointer and value of the holding means An inspection means for comparing the two and inspecting the destruction of the stack pointer.

【0018】第4の発明に係るデータ処理装置は第1〜
第3の発明における選択手段、禁止手段、検査手段を選
択的に動作させることを指定する指定手段を備えたもの
である。
The data processing apparatus according to the fourth aspect of the present invention is
The present invention is provided with a specifying means for specifying that the selecting means, the prohibiting means, and the inspecting means in the third invention are selectively operated.

【0019】[0019]

【作用】第1の発明によれば、選択手段が第1のスタッ
クにPC値やFT値の所定の種類のデータを記憶するよ
うにし、第2のスタックに、PC値やFP値以外の通常
のデータを記憶するようにしたので、第2のスタックが
破壊されるようなことがあっても第1のスタックにある
PC値やFP値等の所定の種類のデータは保護される。
According to the first aspect of the invention, the selecting means stores the predetermined type of data such as the PC value and the FT value in the first stack, and the normal data other than the PC value and the FP value is stored in the second stack. Since the above data is stored, even if the second stack is destroyed, the predetermined type of data such as the PC value and the FP value in the first stack is protected.

【0020】第2の発明によれば、禁止手段がスタック
の使用されている領域への書き込みを禁止するので、ス
タックに退避されたPC値やFP値やその他のデータが
保護される。
According to the second aspect of the invention, since the prohibiting means prohibits writing to the area where the stack is used, the PC value and FP value saved in the stack and other data are protected.

【0021】第3の発明によれは、保持手段で保持した
値と比較してからスタックポインタの値を変更するの
で、スタックポインタの値が正常であることが確認され
てからスタックポインタの値が変更される。
According to the third aspect of the invention, the value of the stack pointer is changed after being compared with the value held by the holding means, so that the value of the stack pointer is changed after it is confirmed that the value of the stack pointer is normal. Be changed.

【0022】第4の発明によれば、指定手段が、選択手
段、禁止手段、検査手段を選択実行を指定するので、デ
バッグ作業が容易に行える。
According to the fourth aspect of the invention, the designating means designates the selecting means, the inhibiting means, and the inspecting means to select and execute, so that the debugging work can be easily performed.

【0023】[0023]

【実施例】【Example】

実施例1.以下この発明の一実施例として、通常のSP
とは別にPC値を退避するスタック(以下PCスタック
とする)を指すスタックポインタとしてPCスタックポ
インタ(以下PCSPとする)を持ち、またPCSPの
初期値を保持するレジスタSR0と、PCSPとともに
変化するレジスタSR1を持ち、デバッグ環境を制御す
るレジスタ中にPC値を退避するのに通常のスタックと
PCスタックのどちらを選択するかを指定するビット
と、PCスタックが選択された場合PCスタックに対す
る書き込みを禁止するかどうかを指定するビットを備え
たデータ処理装置の動作について図1、図2を用いて説
明する。
Example 1. An ordinary SP will be described below as an embodiment of the present invention.
Separately, a PC stack pointer (hereinafter referred to as PCSP) is provided as a stack pointer that points to a stack for saving PC values (hereinafter referred to as PC stack), and a register SR0 that holds the initial value of PCSP and a register that changes together with PCSP A bit that specifies whether to select the normal stack or the PC stack to save the PC value in the register that has SR1 and controls the debug environment, and prohibits writing to the PC stack when the PC stack is selected. The operation of the data processing device provided with the bit for specifying whether or not to carry out will be described with reference to FIGS.

【0024】図1は本発明のデータ処理装置において、
n回のサブルーチンジャンプを連続して行ったときの処
理の流れとJSR前のPCスタックの状態およびn回目
のJSR実行後のPCスタックの状態について示したも
のである。メインプログラムは命令A0、・・・、JS
R、命令C0、・・・からなり、サブルーチン1は命令
A1、・・・、JSR、命令C1、・・・、RTSから
なり、同様にサブルーチンjは命令Aj、・・・、JS
R、命令Cj、・・・、RTSからなる。命令A0、命
令B0、JSR、C0、はそれぞれPC(A0)、PC
(B0)、PC(JS0)、PC(C0)を先頭アドレ
スとするメモリに格納されている。メインプログラムの
JSRのジャンプ先実効アドレスはサブルーチン1の先
頭命令A1が格納されているメモリのアドレスPC(A
1)であるとする。同様にサブルーチンjの命令Aj、
Bj、JSR、Cj、RTSはそれぞれPC(Aj)、
PC(Bj)、PC(JSj)、PC(Cj)、PC
(RTj)を先頭アドレスとするメモリに格納されてお
り、サブルーチンj中のJSRのジャンプ先実効アドレ
スはサブルーチンjの先頭命令A(j+1)が格納され
ているメモリのアドレスPC(A(j+1))であると
する。1回目のJSRが実行される前のPCSPの値を
PCSP(0)、n回目のJSRが実行された後のPC
SPの値をPCSP(n)とする。
FIG. 1 shows a data processing device of the present invention.
It shows the flow of processing when n times of subroutine jumps are continuously performed, the state of the PC stack before JSR, and the state of the PC stack after execution of the nth JSR. The main program is instructions A0, ..., JS
, R, instruction C0, ..., Subroutine 1 comprises instructions A1, ..., JSR, instruction C1, ..., RTS, and similarly, subroutine j comprises instructions Aj ,.
R, instruction Cj, ..., RTS. Instruction A0, instruction B0, JSR, C0 are PC (A0) and PC, respectively.
(B0), PC (JS0), and PC (C0) are stored in the memory having the start address. The jump destination effective address of the JSR of the main program is the address PC (A
1). Similarly, the instruction Aj of the subroutine j,
Bj, JSR, Cj, and RTS are PC (Aj),
PC (Bj), PC (JSj), PC (Cj), PC
(RTj) is stored in the memory having the start address, and the jump destination effective address of the JSR in the subroutine j is the address PC (A (j + 1)) of the memory in which the start instruction A (j + 1) of the subroutine j is stored. Suppose The value of PCSP before the first JSR is executed is PCSP (0), and the PC after the nth JSR is executed
The value of SP is PCSP (n).

【0025】図2の10は本発明のデータ処理装置のデ
バッグ環境制御レジスタを示す。11はPCDビット
で、PC値を通常のスタックに退避するかPCスタック
に退避するかを指定する。12はPCWビットでPCス
タックでSR0からSR1の範囲のメモリを書き込み禁
止にするかどうかを指定する。
Reference numeral 10 in FIG. 2 shows a debug environment control register of the data processor of the present invention. A PCD bit 11 specifies whether to save the PC value in the normal stack or in the PC stack. Reference numeral 12 is a PCW bit that specifies whether or not the PC stack is write-protected for the memory in the range of SR0 to SR1.

【0026】図2のPCDビット11とPCWビット1
2がセットされているとき、メインプログラムを実行す
る前にまずリセット後の初期PCSPの値がSR0とS
R1に転送される。以後SR0の値はリセットがかかる
まで変化しない。メインプログラムの途中で[JSR
PC(A1)]が読み込まれると、PCSPの値をPC
SP(0)からPCSP(1)に変化させ、メインプロ
グラムのJSRの次命令C0の先頭アドレスPC(C
0)を復帰後PC値としてPCスタックにプッシュす
る。PCSPの値が変化すると同時にSR1の値もPC
SP(1)に変化し、常にPCSPとSR1の内容は同
じになる。次にPCにJSRで指定されたジャンプ先実
効アドレスPC(A1)をセットし、サブルーチン1の
処理に移る。PC(A1)を先頭アドレスとする命令A
1から順次命令を読み込んで実行し、サブルーチン1の
途中で[JSR PC(A2)]が読み込まれると、P
CSPをの値はPCSP(1)からPCSP(2)に変
化させ、サブルーチン1のJSRの次命令C1の先頭ア
ドレスPC(C1)をPCスタックにプッシュする。こ
のときSR1の値もPCSP(2)となる。同様に、n
回のサブルーチンジャンプを実行し、サブルーチンnの
処理に移ったときのPCSPの値はPCSP(n)とな
り、SR1の値もPCSP(n)になっている。サブル
ーチンnの最後で[RTS]が読み込まれると、PCス
タックからPCSPの値PCSP(n)を先頭アドレス
として退避していたサブルーチン(n−1)への復帰後
PC値のPC(C(n−1))をポップし、PCにセッ
トしてサブルーチン(n−1)の処理に戻る。PCSP
の値およびSR1の値はPCSP(n−1)になる。同
様にn回のRTS命令によりPCスタックからPC値の
ポップを行うとメインプログラムの処理に戻ることがで
きる。
PCD bit 11 and PCW bit 1 of FIG.
When 2 is set, the value of the initial PCSP after reset is SR0 and S before the main program is executed.
It is transferred to R1. After that, the value of SR0 does not change until reset is applied. In the middle of the main program, click [JSR
PC (A1)] is read, the value of PCSP is changed to PC
It is changed from SP (0) to PCSP (1), and the start address PC (C
After returning 0), it is pushed to the PC stack as the PC value. When the value of PCSP changes, the value of SR1 also changes to PC
It changes to SP (1), and the contents of PCSP and SR1 are always the same. Next, the jump destination effective address PC (A1) designated by JSR is set in the PC, and the process of the subroutine 1 is started. Instruction A with PC (A1) as the start address
When instructions are sequentially read from 1 and executed, and [JSR PC (A2)] is read in the middle of subroutine 1, P
The value of CSP is changed from PCSP (1) to PCSP (2), and the start address PC (C1) of the next instruction C1 of the JSR of subroutine 1 is pushed onto the PC stack. At this time, the value of SR1 also becomes PCSP (2). Similarly, n
The value of PCSP is PCSP (n) and the value of SR1 is also PCSP (n) when the subroutine jump is executed a number of times and the process of the subroutine n is started. When [RTS] is read at the end of the subroutine n, PC (C (n-) of the PC value after returning to the subroutine (n-1) saved from the PC stack with the PCSP value PCSP (n) as the start address is read. 1)) is popped, it is set in the PC, and the process returns to the subroutine (n-1). PCSP
And SR1 become PCSP (n-1). Similarly, if the PC value is popped from the PC stack by n times of RTS instructions, it is possible to return to the processing of the main program.

【0027】サブルーチン中での、全てのメモリへの書
き込み動作に対しては、書き込みを行なうメモリのアド
レスとSR0およびSR1の値を比較し、書き込み動作
を行なうメモリのアドレスがSR0からSR1の範囲内
にあるとき書き込み禁止エラーを発生する。SR0から
SR1の範囲にない場合には書き込みを許可して処理を
続行する。
For the write operation to all the memories in the subroutine, the address of the memory to be written is compared with the values of SR0 and SR1 and the address of the memory to perform the write operation is within the range of SR0 to SR1. A write-prohibit error is generated when If it is not within the range of SR0 to SR1, the writing is permitted and the processing is continued.

【0028】サブルーチン中でのスタックプッシュとポ
ップは通常のSPを使って行い、PCスタックはJSR
のようにPC値をプッシュするような場合にしか使用し
ないこととする。
The stack push and pop in the subroutine are performed using normal SP, and the PC stack is JSR.
It is used only when pushing the PC value as shown in.

【0029】上記の実施例では図2のPCDビット11
とPCWビット12をセットしてPC値のプッシュはP
Cスタックへ行い、PCスタックへの書き込みを禁止す
ることとしたがPCDビット11をクリアすればPC値
も通常のスタックへ退避し、PCDビット12は無視さ
れる。PCDビット11がセットされていてもPCWビ
ット12がクリアされていれば、PC値はPCスタック
へ退避するが、PCスタックへの書き込み動作チェック
は行わない。
In the above embodiment, the PCD bit 11 of FIG.
And PCW bit 12 is set and PC value is pushed by P
Although it is decided to write to the C stack and prohibit writing to the PC stack, if the PCD bit 11 is cleared, the PC value is also saved in the normal stack, and the PCD bit 12 is ignored. If the PCW bit 12 is cleared even if the PCD bit 11 is set, the PC value is saved in the PC stack, but the write operation check to the PC stack is not performed.

【0030】以上のように、この実施例にかかるデータ
処理装置は、通常のスタックを記憶する第二のスタック
とそのスタックポインタである第二のスタックポインタ
と、プログラムカウンタ値退避用のスタックを記憶する
第一のスタックとそのスタックポインタである第一のス
タックポインタと、前記第一のスタックポインタの初期
値を保持する第一の保持手段と、前記第一のスタックポ
インタの値の変化にともなって前記第一のスタックポイ
ンタ値と同じ値を保持する第二の保持手段と、プログラ
ムカウンタ値を第一のスタックに退避するかどうか選択
する選択手段と、前記第一の保持手段と前記第二の保持
手段とで指定される第一のスタックの領域に対する書き
込みを禁止する禁止手段を備えるものである。
As described above, the data processing apparatus according to this embodiment stores the second stack that stores the normal stack, the second stack pointer that is the stack pointer, and the stack for saving the program counter value. A first stack and a first stack pointer which is the stack pointer thereof, a first holding means for holding an initial value of the first stack pointer, and a change in the value of the first stack pointer. Second holding means for holding the same value as the first stack pointer value, selecting means for selecting whether or not to save the program counter value in the first stack, the first holding means, and the second The holding unit is provided with a prohibiting unit that prohibits writing to the area of the first stack.

【0031】また、この実施例によれば、デバッグ環境
を制御するレジスタ中にPC値を通常のスタックとは別
のスタックに退避するかどうか指定するビットがセット
されているときPC値を通常のスタックとは別のスタッ
クに退避し、デバッグ環境を制御するレジスタ中に通常
のスタックとは別のスタックに対する書き込みを禁止す
るかどうか指定するビットがセットされているとき、通
常のスタックとは別のスタック用のスタックポインタの
初期値を保持する第一の保持手段と、サブルーチン用命
令実行後の通常のスタックとは別のスタックのスタック
ポインタ値を保持する第二の保持手段とで指定される領
域に対する書き込みを禁止し、この領域にデータを書き
込もうとした場合、エラーを発生して処理を中断する。
Further, according to this embodiment, when the bit for designating whether to save the PC value to a stack different from the normal stack is set in the register for controlling the debug environment, the PC value is set to the normal PC value. Save to a stack different from the stack, and if the register that controls the debug environment has the bit that specifies whether writing to the stack different from the normal stack is set, Area designated by the first holding means for holding the initial value of the stack pointer for the stack and the second holding means for holding the stack pointer value of a stack different from the normal stack after the execution of the subroutine instruction When writing to this area is prohibited and an attempt is made to write data to this area, an error occurs and the processing is interrupted.

【0032】以上説明したように、この実施例によれ
ば、スタックに退避したPC値を不用意なデータの上書
きから保護し、またPC値を退避するスタックを通常の
データのプッシュポップを行なうスタックと分けること
でPC値を退避しているスタックのスタックポインタ値
を変化させないので、誤ったPC値を読み込むことによ
るプログラムの流れの変化や暴走を防ぐことができ、プ
ログラムそのものやデータを守ることができるという効
果がある。また前ルーチンのPC値を保護してあること
でデバッグが容易になるという効果がある。
As described above, according to this embodiment, the PC value saved in the stack is protected from inadvertent overwriting of data, and the stack for saving the PC value is a stack for performing normal data push-pop. Since the stack pointer value of the stack that saves the PC value is not changed by dividing it with, it is possible to prevent the flow of the program from changing and runaway due to reading an incorrect PC value, and to protect the program itself and data. There is an effect that you can. In addition, the PC value of the previous routine is protected, which facilitates debugging.

【0033】実施例2.以下この発明の一実施例とし
て、通常のSPとは別にPC値を退避するスタック(以
下PCスタックとする)を指すスタックポインタとして
PCスタックポインタ(以下PCSPとする)を持ち、
またPCSPの初期値を保持するレジスタSR0とJS
R実行後のPCSPの値を保持するレジスタSR1を持
ち、ENTER実行後のSPの値を保持するレジスタS
R2を持ち、デバッグ環境を制御するレジスタ中にPC
値を退避するのに通常のスタックとPCスタックのどち
らを選択するかを指定するビットと、FP値を退避する
のに通常のスタックとPCスタックのどちらを選択する
かを指定するビットと、PC値またはFP値の退避にP
Cスタックが選択された場合PCスタックに対する書き
込みを禁止するかどうかを指定するビットを備えたデー
タ処理装置の動作について図3、図4を用いて説明す
る。
Example 2. Hereinafter, as one embodiment of the present invention, a PC stack pointer (hereinafter referred to as PCSP) is provided as a stack pointer that points to a stack (hereinafter referred to as PC stack) for saving a PC value separately from a normal SP,
In addition, registers SR0 and JS that hold the initial value of PCSP
Register S that holds the value of PCSP after execution of R, and register S that holds the value of SP after execution of ENTER
PC with R2 in the register that controls the debug environment
A bit that specifies whether to select the normal stack or the PC stack to save the value, a bit that specifies whether to select the normal stack or the PC stack to save the FP value, and the PC P to save the value or FP value
When the C stack is selected, the operation of the data processing device having a bit for designating whether or not writing to the PC stack is prohibited will be described with reference to FIGS. 3 and 4.

【0034】図3は本発明のデータ処理装置において、
メインプログラムの途中でJSRによりサブルーチン1
を呼び出した後ENTERを実行するときの処理の流れ
と、ENTERを実行する前のスタックの状態、および
ENTERを実行した後のスタックの状態について説明
したものである。図3でメインプログラムは命令A0、
B0、JSR、およびC0からなり、サブルーチン1は
ENTER、・・・、EXITDからなる。命令A0が
格納されているメモリの先頭アドレスを、PC(A
0)、同様に命令B0、JSR、C0、ENTER、E
XITDが格納されているメモリの先頭アドレスを、そ
れぞれPC(B0)、PC(JSR)、PC(C0)、
PC(EN)、PC(EX)とする。JSRのジャンプ
先実効アドレスはサブルーチン1の先頭命令ENTER
が格納されているメモリの先頭アドレスPC(EN)で
あるとする。JSRが実行される前のSP、FP、PC
SPの値をそれぞれSP(0)、FP(0)、PCSP
(0)、JSRが実行された後のPCSPの値をPCS
P(1)、ENTERが実行された後のSP、PCSP
の値をそれぞれSP(1)、PCSP(2)とする。
FIG. 3 shows the data processing device of the present invention.
Subroutine 1 by JSR in the middle of the main program
This is a description of the flow of processing when executing ENTER after calling, the state of the stack before executing ENTER, and the state of the stack after executing ENTER. In FIG. 3, the main program is instruction A0,
It consists of B0, JSR, and C0, and subroutine 1 consists of ENTER, ..., EXITD. The start address of the memory where the instruction A0 is stored is PC (A
0), as well as the instructions B0, JSR, C0, ENTER, E
The start address of the memory in which XITD is stored is PC (B0), PC (JSR), PC (C0),
PC (EN) and PC (EX). The jump destination effective address of JSR is the start instruction ENTER of subroutine 1.
Is the start address PC (EN) of the memory in which is stored. SP, FP, PC before JSR is executed
The SP values are SP (0), FP (0), and PCSP, respectively.
(0), PCS value of PCSP after JSR is executed
P (1), SP after PC ENTER is executed, PCSP
Let SP (1) and PCSP (2) be the values of, respectively.

【0035】図4の10はデバッグ環境制御レジスタを
示す。11はPCDビットで、PC値を通常のスタック
に退避するかPCスタックに退避するかを指定する。1
2はFPDビットで、FP値を通常のスタックに退避す
るかPCスタックに退避するかを指定する。13はPC
Wビット(1ビット)でPCスタックでSR0からS
Reference numeral 10 in FIG. 4 indicates a debug environment control register. A PCD bit 11 specifies whether to save the PC value in the normal stack or in the PC stack. 1
Reference numeral 2 denotes an FPD bit, which specifies whether to save the FP value in the normal stack or the PC stack. 13 is a PC
W bit (1 bit) PC stack with SR0 to S

【0036】図4のPCDビット11とFPDビット1
2、PCWビット13がセットされているとき、メイン
プログラムを実行する前にまずリセット後の初期PCS
Pの値がSR0とSR1に転送される。以後SR0の値
はリセットがかかるまで変化しない。メインプログラム
の途中で[JSR PC(EN)]が読み込まれると、
PCSPの値をPCSP(0)からPCSP(1)に変
化させ、メインプログラムのJSRの次命令C0の先頭
アドレスPC(C0)を復帰後PC値としてスタックに
プッシュする。PCSPの値が変化すると同時にSR1
の値もPCSP(1)に変化し、常にPCSPとSR1
の内容は同じになる。次にPCにJSRで指定されたジ
ャンプ先実効アドレスPC(EN)をセットし、サブル
ーチン1の処理に移る。サブルーチン1の先頭命令EN
TERを読み込んで実行すると、まずPCSPとSR1
の値をPCSP(1)からPCSP(2)に変化させて
ENTER実行前のFPの値FP(0)をPCスタック
にプッシュし、FPにはSPの値SP(0)を新FP値
として格納する。その後スタックにローカル変数領域を
確保してから汎用レジスタ群をプッシュする。ENRE
Rの全てのスタックプッシュが終わったときSPの値は
SP(2)となり、同時にSR2の値もSP(2)とな
っている。ENTER処理後サブルーチン1の処理を実
行し、サブルーチン1の最後で[EXITD]が読み込
まれると、SPの値とSR2の値を比較し、一致した場
合スタックからSPの値SP(2)を先頭アドレスとし
てまず汎用レジスタ群の値をポップし、FPの値SP
(0)をSPに格納してローカル変数領域を開放する。
次に、PCスタックから退避していた前ルーチンFP値
FP(0)をポップしてFPに格納する。PCSPはP
CSP(2)からPCSP(1)に変化する。その後P
Cスタックから復帰後PC値をポップしてPCにセット
し、メインプログラムの処理に戻る。PCSPの値はP
CSP(0)にもどっている。
PCD bit 11 and FPD bit 1 of FIG.
2. When the PCW bit 13 is set, first reset the initial PCS before executing the main program.
The value of P is transferred to SR0 and SR1. After that, the value of SR0 does not change until reset is applied. When [JSR PC (EN)] is read in the middle of the main program,
The value of PCSP is changed from PCSP (0) to PCSP (1), and the head address PC (C0) of the next instruction C0 of the JSR of the main program is pushed onto the stack as the PC value after restoration. SR1 as soon as the value of PCSP changes
Also changes to PCSP (1), and always PCSP and SR1
Will be the same. Next, the jump destination effective address PC (EN) designated by JSR is set in the PC, and the processing of the subroutine 1 is started. First instruction EN of subroutine 1
When TER is read and executed, first, PCSP and SR1
Value of PC is changed from PCSP (1) to PCSP (2), the value FP (0) of FP before ENTER is pushed to the PC stack, and the value SP (0) of SP is stored in FP as a new FP value. To do. After that, the local variable area is secured on the stack and then the general-purpose register group is pushed. ENRE
When all stack pushes of R are completed, the value of SP becomes SP (2), and at the same time, the value of SR2 also becomes SP (2). After the ENTER processing, the processing of subroutine 1 is executed, and when [EXIT] is read at the end of subroutine 1, the SP value and the SR2 value are compared, and if they match, the SP value SP (2) from the stack is the start address. First, pop the values in the general-purpose register group, and then add the FP value SP
(0) is stored in SP and the local variable area is released.
Next, the previous routine FP value FP (0) saved from the PC stack is popped and stored in FP. PCSP is P
Change from CSP (2) to PCSP (1). Then P
After returning from the C stack, the PC value is popped and set in the PC, and the process returns to the main program. PCSP value is P
Returning to CSP (0).

【0037】上記の実施例ではEXITが読み込まれた
ときのSPとSR2が一致した場合について説明した
が、SPとSR2が一致しない場合にはエラーを発生す
る。
In the above embodiment, the case where SP and SR2 match when EXIT is read has been described, but an error occurs when SP and SR2 do not match.

【0038】サブルーチン中での、全てのメモリへの書
き込み動作に対しては、書き込みを行なうメモリのアド
レスとSR0およびSR1の値を比較し、書き込み動作
を行なうアドレスがSR0からSR1の範囲内にあると
き書き込み禁止エラーを発生する。SR0からSR1の
範囲にない場合には書き込みを許可して処理を続行す
る。
For the write operation to all memories in the subroutine, the address of the memory to be written is compared with the values of SR0 and SR1 and the address to perform the write operation is within the range of SR0 to SR1. When a write-protect error occurs. If it is not within the range of SR0 to SR1, the writing is permitted and the processing is continued.

【0039】サブルーチン中でのスタックプッシュとポ
ップは通常のSPを使って行い、PCスタックはPC値
とFP値をプッシュするような場合にしか使用しないこ
ととする。
The stack push and pop in the subroutine are performed by using the normal SP, and the PC stack is used only when pushing the PC value and the FP value.

【0040】上記の実施例では図4のPCDビット11
とFPDビット12、PCWビット13をセットしてP
C値とFP値のプッシュはPCスタックへ行い、PCス
タックへの書き込みを禁止することとしたが、PCDビ
ット11とFPDビット12をクリアすればPC値とF
P値も通常のスタックへ退避し、PCDビット13は無
視される。PCDビット11とFPDビットがセットさ
れていてもPCWビット12がクリアされていれば、P
C値とFP値はPCスタックへ退避するが、PCスタッ
クへの書き込み動作チェックは行わない。
In the above embodiment, the PCD bit 11 of FIG.
And FPD bit 12 and PCW bit 13 are set to P
The C value and FP value are pushed to the PC stack, and writing to the PC stack is prohibited. However, if the PCD bit 11 and the FPD bit 12 are cleared, the PC value and the F value are deleted.
The P value is also saved in the normal stack and PCD bit 13 is ignored. If PCW bit 12 is cleared even if PCD bit 11 and FPD bit are set, P
Although the C value and the FP value are saved in the PC stack, the write operation check to the PC stack is not performed.

【0041】以上のように、この発明にかかるデータ処
理装置は、通常の第二のスタックを指す第二のスタック
ポインタと、プログラムカウンタ値退避用の第一のスタ
ックを指す第一のスタックポインタと、スタックフレー
ムを指すフレームポインタと、前記第一のスタックポイ
ンタの初期値を保持する第一の保持手段と、前記第一の
スタックポインタの値の変化にともなって前記第一のス
タックポインタ値と同じ値を保持する第二の保持手段
と、スタックフレーム形成直後の直後の前記第二のスタ
ックポインタの値を保持する第三の保持手段と、プログ
ラムカウンタ値を通常のスタックに退避するかプログラ
ムカウンタ値退避用のスタックに退避するかを選択する
選択手段と、前記第一の保持手段と前記第二の保持手段
とで指定されるプログラムカウンタ値退避用のスタック
に対する書き込みを禁止する禁止手段を備えるものであ
る。
As described above, the data processing device according to the present invention includes the second stack pointer which indicates the normal second stack, and the first stack pointer which indicates the first stack for saving the program counter value. A frame pointer that points to a stack frame, a first holding unit that holds the initial value of the first stack pointer, and the same value as the first stack pointer value with a change in the value of the first stack pointer. A second holding means for holding the value, a third holding means for holding the value of the second stack pointer immediately after the formation of the stack frame, and a program counter value for saving the program counter value in a normal stack Selection means for selecting whether to save to the stack for saving, and a program designated by the first holding means and the second holding means. Those comprising inhibiting means for inhibiting writing to the stack of ram counter value cache.

【0042】また、この実施例によれば、デバッグ環境
を制御するレジスタ中にPC値を通常のスタックとは別
のスタックに退避するかどうか指定するビットがセット
されているときPC値を通常のスタックとは別のスタッ
クに退避し、デバッグ環境を制御するレジスタ中にFP
値を通常のスタックとは別のスタックに退避するかどう
か指定するビットがセットされているときFP値を通常
のスタックとは別のスタックに退避し、デバッグ環境を
制御するレジスタ中に通常のスタックとは別のスタック
に対する書き込みを禁止するかどうか指定するビットが
セットされているとき、通常のスタックとは別のスタッ
ク用のスタックポインタの初期値を保持する第一の保持
手段と、サブルーチン用命令実行後の通常のスタックと
は別のスタックのスタックポインタ値を保持する第二の
保持手段とで指定される領域に対する書き込みを禁止
し、この領域にデータを書き込もうとした場合、エラー
を発生して処理を中断しする。またスタックフレーム開
放命令を実行するときに通常のスタックを指すスタック
ポインタの値とスタックフレーム形成命令実行後の通常
のスタックのスタックポインタ値を保持する第三の保持
手段とが一致しない場合もエラーを発生して処理を中断
する。
Further, according to this embodiment, when the bit for designating whether to save the PC value to a stack different from the normal stack is set in the register for controlling the debug environment, the PC value is set to the normal value. Saves to a stack other than the stack and stores FP in the register that controls the debug environment.
When the bit that specifies whether to save the value to a different stack from the normal stack is set, the FP value is saved to a different stack from the normal stack, and the normal stack is saved in the register that controls the debug environment. When the bit that specifies whether writing to a stack other than the above is prohibited, the first holding means for holding the initial value of the stack pointer for the stack different from the normal stack, and the instruction for the subroutine If you prohibit writing to the area specified by the second holding means that holds the stack pointer value of a stack different from the normal stack after execution, and try to write data to this area, an error will occur. Suspend processing. Also, when the stack frame release instruction is executed and the value of the stack pointer that points to the normal stack does not match the third holding means that holds the stack pointer value of the normal stack after the execution of the stack frame formation instruction, an error is generated. Occurs and interrupts processing.

【0043】以上説明したようにこの実施例によれば、
スタックに退避した前ルーチンのPC値やFP値を不用
意なデータの上書きから保護し、またPC値やFP値を
退避するスタックを通常のデータのプッシュポップを行
なうスタックと分けることでサブルーチンコール後のP
C値やFP値を退避しているスタックのスタックポイン
タ値を変化させないので、誤ったFP値やPC値を読み
込むことによるプログラムの流れの変化や暴走を防ぐこ
とができ、プログラムそのものやデータを守ることがで
きるという効果がある。また前ルーチンのPC値を保護
してあることでデバッグが容易になるという効果があ
る。さらにスタックフレームを形成直後のSP値を保持
し、EXIT実行時にSP値と比較するので、誤ったレ
ジスタ値をポップしてしまうことを防ぐという効果があ
る。
As described above, according to this embodiment,
After the subroutine call by protecting the PC value and FP value of the previous routine saved in the stack from inadvertent overwriting of data, and separating the stack that saves the PC value and FP value from the stack that performs normal data push-pop Of P
Since the stack pointer value of the stack that saves the C value and FP value is not changed, it is possible to prevent changes in the program flow or runaway caused by reading the wrong FP value or PC value, and protect the program itself and data. The effect is that you can. In addition, the PC value of the previous routine is protected, which facilitates debugging. Furthermore, since the SP value immediately after forming the stack frame is held and compared with the SP value at the time of executing EXIT, there is an effect of preventing an incorrect register value from being popped.

【0044】[0044]

【発明の効果】以上のように、第1の発明によれば、ス
タックを2つに分けたので一方のスタックが破壊される
場合でも他方のデータは保護される。
As described above, according to the first invention, since the stack is divided into two, even if one stack is destroyed, the other data is protected.

【0045】また、第2の発明によれば、スタックへの
書き込みを禁止したので、スタックのデータが保護され
る。
Further, according to the second aspect of the invention, since writing to the stack is prohibited, the data in the stack is protected.

【0046】また、第3の発明によれば、スタックポイ
ンタの値を別個に保持しているので、スタックポインタ
の値の正常性が検査できる。
Further, according to the third invention, since the value of the stack pointer is held separately, it is possible to check the normality of the value of the stack pointer.

【0047】また、第4の発明によれば、上記第1〜3
の発明を選択的に動作させることができるので、デバッ
グ時に用いることでデバッグ作業が容易になる。
Further, according to the fourth invention, the above-mentioned first to third
Since the invention of (1) can be selectively operated, the debugging work becomes easy by using it when debugging.

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

【図1】本発明のデータ処理装置でn回のサブルーチン
ジャンプを連続して行ったときの処理の流れと1回目の
JSR前のスタック領域の状態およびn回目のJSR実
行後のスタック領域の状態について示した図である。
FIG. 1 is a flow chart of processing when n sub-routine jumps are continuously performed in a data processing device of the present invention, a state of a stack area before the first JSR, and a state of a stack area after execution of the n-th JSR. It is the figure shown about.

【図2】本発明のデータ処理装置のデバッグ環境を制御
するレジスタを示した図である。
FIG. 2 is a diagram showing registers that control a debug environment of the data processing device of the present invention.

【図3】本発明のデータ処理装置でENTER命令を実
行したときの処理の流れとENTER実行後のPCスタ
ックおよびスタックの状態について示した図である。
FIG. 3 is a diagram showing a flow of processing when an ENTER instruction is executed in the data processing device of the present invention, and a PC stack and a state of the stack after execution of the ENTER.

【図4】本発明のデータ処理装置のデバッグ環境を制御
するレジスタを示した図である。
FIG. 4 is a diagram showing registers that control a debug environment of the data processing device of the present invention.

【図5】従来のデータ処理装置でメインプログラムを実
行途中にJSRによりサブルーチン1を呼び出したとき
の処理の流れとJSR実行前後のスタック領域の状態に
ついて示した図である。
FIG. 5 is a diagram showing a flow of processing when a subroutine 1 is called by JSR while a main program is being executed in a conventional data processing device, and a state of a stack area before and after execution of JSR.

【図6】従来のデータ処理装置でn回のサブルーチンジ
ャンプを連続して行ったときの処理の流れと1回目のJ
SR前のスタック領域の状態およびn回目のJSR実行
後のスタック領域の状態について示した図である。
FIG. 6 is a flow of processing when a conventional data processing device performs n times of subroutine jumps in succession and the first J
It is the figure which showed the state of the stack area | region before SR and the state of the stack area | region after execution of n-th JSR.

【図7】従来のデータ処理装置でメインプログラムを実
行途中にJSRによりサブルーチン1を呼び出した後E
NTERを実行するときの処理の流れと、ENTERを
実行する前のスタックの状態、およびENTERを実行
した後のスタックの状態について説明した図である。
[FIG. 7] E after calling subroutine 1 by JSR during execution of a main program in a conventional data processing device
It is a figure explaining the flow of processing at the time of performing NTER, the state of the stack before performing ENTER, and the state of the stack after performing ENTER.

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

10 本発明のデバッグ環境を制御するレジスタ 11 PCDビット 12 FPDビット 13 PCWビット 10 Register for controlling debug environment of the present invention 11 PCD bit 12 FPD bit 13 PCW bit

Claims (4)

【特許請求の範囲】[Claims] 【請求項1】 以下の要素を有するデータ処理装置
(a)所定の種類のデータを記憶する第1のスタック、
(b)上記第1のスタックに記憶されるデータ以外のデ
ータを記憶する第2のスタック、(c)データをスタッ
クに記憶する場合、そのデータの種類により上記第1と
第2のスタックのいずれかを選択する選択手段。
1. A data processing device comprising: (a) a first stack for storing data of a predetermined type;
(B) a second stack that stores data other than the data stored in the first stack; (c) when storing data in the stack, whichever of the first and second stacks is used depending on the type of the data. Selection means for selecting or.
【請求項2】 以下の要素を備えたデータ処理装置
(a)所定のデータを記憶するスタック、(b)上記ス
タックの使用されている領域への書き込みを禁止する禁
止手段。
2. A data processing device comprising: (a) a stack that stores predetermined data; and (b) a prohibition unit that prohibits writing to a used area of the stack.
【請求項3】 以下の要素を備えたデータ処理装置
(a)所定のデータを記憶するスタック、(b)上記ス
タックの先頭を示すスタックポインタ、(c)上記スタ
ックポインタの値を保持する保持手段、(d)上記スタ
ックポインタの値と保持手段の値を比較してスタックポ
インタの破壊を検査する検査手段。
3. A data processing device comprising: (a) a stack for storing predetermined data; (b) a stack pointer indicating the beginning of the stack; and (c) a holding means for holding the value of the stack pointer. , (D) inspection means for inspecting the destruction of the stack pointer by comparing the value of the stack pointer with the value of the holding means.
【請求項4】 請求項1,2または3記載のデータ処理
装置において、選択手段、禁止手段、あるいは、検査手
段を選択的に動作させることを指定する指定手段を有す
ることを特徴とする請求項1,2または3記載のデータ
処理装置。
4. The data processing device according to claim 1, 2, or 3, further comprising a specifying unit that specifies that the selecting unit, the prohibiting unit, or the checking unit is selectively operated. The data processing device according to 1, 2, or 3.
JP4000666A 1992-01-07 1992-01-07 Data processor Pending JPH05181703A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP4000666A JPH05181703A (en) 1992-01-07 1992-01-07 Data processor

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP4000666A JPH05181703A (en) 1992-01-07 1992-01-07 Data processor

Publications (1)

Publication Number Publication Date
JPH05181703A true JPH05181703A (en) 1993-07-23

Family

ID=11480067

Family Applications (1)

Application Number Title Priority Date Filing Date
JP4000666A Pending JPH05181703A (en) 1992-01-07 1992-01-07 Data processor

Country Status (1)

Country Link
JP (1) JPH05181703A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5953529A (en) * 1995-10-31 1999-09-14 Nec Corporation Data processor with a debug device and a stack area control unit and corresponding data processing method
WO2005020069A1 (en) * 2003-08-25 2005-03-03 Denki Hompo Ltd. Cpu (central processing unit) of a computer system

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US5953529A (en) * 1995-10-31 1999-09-14 Nec Corporation Data processor with a debug device and a stack area control unit and corresponding data processing method
WO2005020069A1 (en) * 2003-08-25 2005-03-03 Denki Hompo Ltd. Cpu (central processing unit) of a computer system

Similar Documents

Publication Publication Date Title
JP4476193B2 (en) Information processing method and information processing apparatus
US7711914B2 (en) Debugging using virtual watchpoints
JP2850808B2 (en) Data processing device and data processing method
US20060294433A1 (en) Debugging using watchpoints
US7293266B2 (en) Plurality of loader modules with a CO- ordinator module where selected loader module executes and each loader module execute
JPH05181703A (en) Data processor
JP2000029690A (en) Method and device for data processing
JPS6042495B2 (en) Method of accessing privileged memory of a multi-program data processing device
KR100928865B1 (en) Stack expansion and protection methods in computer systems and devices therefor
CN100361105C (en) Method and apparatus for recovering access environment setting-up in interrupt processing
JP2504151B2 (en) Data processing device
JPH08249206A (en) Computer with stack area destruction detection function
JPH04322343A (en) Trace system for memory access
JPH07210420A (en) Debugging method in thread environment
JPH0944413A (en) Page boundary testing method
JPH05257807A (en) Cache memory controller
JPS60112148A (en) Memory device
JPH07210421A (en) Debugging method in thread environment
JPH05289944A (en) Debugging system for illegal writing in memory space
JPH03214324A (en) Computer system
JPH05204764A (en) Ring protecting system for memory protect
JP2002014843A (en) Program execution trace system
JPS63153650A (en) Memory dump system
JPH08235029A (en) Storage method for system fault information
JPS61134850A (en) Debugging method of subsequent processor