JPH09198258A - Task stack overflow detecting circuit - Google Patents

Task stack overflow detecting circuit

Info

Publication number
JPH09198258A
JPH09198258A JP734196A JP734196A JPH09198258A JP H09198258 A JPH09198258 A JP H09198258A JP 734196 A JP734196 A JP 734196A JP 734196 A JP734196 A JP 734196A JP H09198258 A JPH09198258 A JP H09198258A
Authority
JP
Japan
Prior art keywords
task
stack
upper limit
limit value
address
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
JP734196A
Other languages
Japanese (ja)
Inventor
Hanae Sawa
花江 澤
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.)
NEC Corp
Original Assignee
NEC Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by NEC Corp filed Critical NEC Corp
Priority to JP734196A priority Critical patent/JPH09198258A/en
Publication of JPH09198258A publication Critical patent/JPH09198258A/en
Pending legal-status Critical Current

Links

Landscapes

  • Executing Machine-Instructions (AREA)

Abstract

PROBLEM TO BE SOLVED: To instantaneously detect a task stack overflow and to improve the reliability of a stack by interrupting a CPU when an address value on an address line exceeds a set stack upper limit value. SOLUTION: At the time of starting a task A, a stack upper limit value is read out from a task control block 5 and the read value is set up in a task stack upper limit value setting register 1. During the execution of the task A, an address matching circuit 2 compares the value of the register 1 with the address value on the address line 4, and when a stack address exceeding the upper limit value of the task A is read out/written, the CPU 3 is interrupted to inform the CPU 3 of the generation of a stack overflow. When task switching from the task A to a task B is generated, a stack upper limit value is read out from the block at the time of starting the task B and the read value is reset in the register 1.

Description

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

【0001】[0001]

【発明の属する技術分野】本発明はタスクスタックオー
バーフロー検出回路に関し、特にマルチタスク構成のソ
フトウエアで制御される装置のタスクスタックオーバー
フロー検出回路に関する。
BACKGROUND OF THE INVENTION 1. Field of the Invention The present invention relates to a task stack overflow detection circuit, and more particularly to a task stack overflow detection circuit for a device controlled by software having a multitask structure.

【0002】[0002]

【従来の技術】従来のスタックオーバーフロー検出方式
としては、 (1)ネスティングの重畳度を記憶する記憶領域を記憶
手段に割り当て、記憶領域の記憶内容が予め定めた値を
超過したときにマイクロコンピュータをリセットするも
の(特開平1−241629号) (2)読み出された記憶保護コードが特定の記憶保護コ
ードで、かつアクセスコードが書き込みを指定している
場合には、書き込み割り込み領域にデータを書き込むこ
とにより、スタック領域のオーバーフローをCPUに伝
えるもの(特公平2−9373号)がある。
2. Description of the Related Art As a conventional stack overflow detection method, (1) a storage area for storing a nesting superposition degree is assigned to a storage means, and a microcomputer is activated when the storage content of the storage area exceeds a predetermined value. What is reset (Japanese Patent Laid-Open No. 1-241629) (2) When the read storage protection code is a specific storage protection code and the access code specifies writing, write data in the write interrupt area Therefore, there is one (Japanese Patent Publication No. 2-9373) that informs the CPU of the overflow of the stack area.

【0003】[0003]

【発明が解決しようとする課題】前者のスタックオーバ
ーフロー検出方式における問題点は、ネスティングの数
でスタックオーバーフローを判断することである。なぜ
ならば、もともとの正常動作で多くのネスティングを必
要とする場合これをスタックオーバーフローとしてしま
ったり、ネスティングは少なくてもスタックをオーバー
フローする可能性のある場合にこれを検出できなかった
りと、誤動作を起こすからである。
The problem with the former stack overflow detection method is that the stack overflow is determined by the number of nesting. This is because if the original normal operation requires a lot of nesting, it will be referred to as a stack overflow. Because.

【0004】後者のスタックオーバーフロー検出方式に
おける問題点は、アクセスを禁ずるべきスタックオーバ
ーの領域に記憶保護コードを設定しておかなければなら
ないことである。その理由は、マルチタスクの場合には
タスクスイッチする度にスタック領域が変わるので、そ
の度に記憶保護コードを付け替える必要があり、処理性
能が遅くなるという問題があると思われるからである。
A problem with the latter stack overflow detection method is that a memory protection code must be set in a stackover area where access should be prohibited. The reason for this is that in the case of multitasking, the stack area changes each time a task is switched, so it is necessary to change the memory protection code every time, and there seems to be a problem that the processing performance becomes slow.

【0005】一般に、タスクスタック量は、タスクの動
作内容から見積もったり、代表的な動作をシミュレーシ
ョンして見積もったりした大きさで設定しているため、
予想外の動作時にタスクスタックオーバーフローが発生
してしまう可能性がわずかながら残ってしまう。
In general, the task stack amount is set as a size estimated from the operation contents of the task or simulated by simulating a typical operation.
There is a slight possibility that a task stack overflow will occur during an unexpected operation.

【0006】また、本当は自タスクのスタック領域をオ
ーバーして他タスクのスタックを破壊しているのに、た
またまその時他タスクが起動されなかったためにうまく
動作しているように見えていて、後になってから影響が
出ることもある。
Further, although the stack area of the own task is actually exceeded and the stack of the other task is destroyed, it seems that the other task does not start up at that time, and it seems that it is working well. It may have an impact later.

【0007】本発明の目的は、タスクスタックオーバー
フローを確実に、しかも即座に検出することにより、上
記のようなことをなくし、タスクスタックの信頼性を向
上させるタスクスタックオーバーフロー検出回路を提供
することである。
An object of the present invention is to provide a task stack overflow detection circuit which detects the task stack overflow surely and immediately and eliminates the above and improves the reliability of the task stack. is there.

【0008】[0008]

【課題を解決するための手段】本発明のタスクスタック
オーバーフロー検出回路は、各タスクのスタック上限値
が設定されるスタック上限値設定レジスタと、アドレス
線上のアドレス値をスタック上限値設定レジスタに設定
されているスタック上限値と比較し、該アドレス値が該
スタック上限値を越えた場合、CPUに割り込みを入れ
るアドレスマッチング回路を有する。
In the task stack overflow detection circuit of the present invention, the stack upper limit value setting register in which the stack upper limit value of each task is set and the address value on the address line are set in the stack upper limit value setting register. The address matching circuit has an address matching circuit for interrupting the CPU when the address value exceeds the stack upper limit value.

【0009】タスクスタックへのアクセスがあると、ア
ドレスマッチング回路はこのアクセスアドレスとスタッ
ク上限値設定レジスタの設定値を比較する。これによ
り、スタック上限値をこえたアクセスを即座に検出し
て、CPUに割り込みをかける。
When the task stack is accessed, the address matching circuit compares the access address with the set value of the stack upper limit value setting register. As a result, an access that exceeds the stack upper limit value is immediately detected, and the CPU is interrupted.

【0010】本発明のスタックオーバーフロー検出回路
は、タスク生成時にタスクスタック量から検出されたス
タック上限値が書き込まれるタスクコントロールブロッ
クをさらに有し、タスク起動時に前記タスクコントロー
ルブロックからスタック上限値が読み出されてスタック
上限値設定レジスタに設定される。
The stack overflow detection circuit of the present invention further has a task control block in which the stack upper limit value detected from the task stack amount at the time of task generation is written, and the stack upper limit value is read from the task control block at the time of task activation. It is set in the stack upper limit value setting register.

【0011】プログラムにより各タスク起動時にそのタ
スクのスタック上限値をスタック上限値設定レジスタに
設定すれば、タスクスイッチが起こってもスタックオー
バーフローを正しく検出できる。
If the stack upper limit value of the task is set in the stack upper limit value setting register at the start of each task by the program, the stack overflow can be correctly detected even if the task switch occurs.

【0012】[0012]

【発明の実施の形態】次に、本発明の実施形態について
図面を参照して証明する。
DESCRIPTION OF THE PREFERRED EMBODIMENTS Next, embodiments of the present invention will be proved with reference to the drawings.

【0013】図1は本発明の一実施形態のタスクスタッ
クオーバーフロー検出回路のブロック図である。
FIG. 1 is a block diagram of a task stack overflow detection circuit according to an embodiment of the present invention.

【0014】本タスクスタックオーバーフロー検出回路
は、各タスクのスタック上限値が設定されるスタック上
限値設定レジスタ1と、スタック上限値設定レジスタ1
の値と、アドレス線4上のアドレス値とを比較して、ス
タック上限値を越えるスタックアドレスをリード/ライ
トした場合に、CPU3に割り込みを入れるアドレスマ
ッチング回路2と、プログラムにより、タスク生成時
に、スタック用メモリ領域6のタスクスタック量から算
出されたスタック上限値が書き込まれ、タスク起動時お
よびタスクスイッチ時に、該スタック上限値が読み出さ
れてスタック上限値設定レジスタ1に設定されるタスク
コントロールブロック5から構成される。なお、タスク
スタックの大きさはプログラムのパラメータによりタス
クごとに設定される。
This task stack overflow detection circuit includes a stack upper limit value setting register 1 in which the stack upper limit value of each task is set, and a stack upper limit value setting register 1
Value is compared with the address value on the address line 4, and when a stack address exceeding the stack upper limit value is read / written, the address matching circuit 2 that interrupts the CPU 3 and the program generate a task, A task control block in which the stack upper limit value calculated from the task stack amount in the stack memory area 6 is written, and the stack upper limit value is read at the time of task activation and task switch and set in the stack upper limit value setting register 1. It consists of 5. The size of the task stack is set for each task by the program parameters.

【0015】次に、本実施形態の動作について説明す
る。
Next, the operation of this embodiment will be described.

【0016】タスクAが生成されると、オペレーション
システムプログラムにより、スタック用メモリ領域6に
タスクAのスタック領域が割り当てられ、タスクAのス
タックボトムアドレスが決定する。次に、プログラムの
パラメータで指定されたタスクスタック量と、割り当て
られたタスクスタックのボトムアドレスとからタスクス
タック上限値が算出される。例えば、プログラムのパラ
メータでタスクAのスタック量は1000バイトが指定
され、タスクスタックのボトムアドレスとして2000
1000番地が割り当てられたとする。このとき、スタ
ック上限値は、20001000−1000=2000
0000番地となる。算出されたスタック上限値はタス
クコントロールブロック5に書き込まれる。タスクBが
生成されたときも同様である。
When the task A is generated, the stack area of the task A is allocated to the stack memory area 6 by the operation system program, and the stack bottom address of the task A is determined. Next, the task stack upper limit value is calculated from the task stack amount specified by the program parameters and the assigned bottom address of the task stack. For example, the stack amount of task A is specified by the program parameter as 1000 bytes, and the bottom address of the task stack is 2000 bytes.
It is assumed that address 1000 is assigned. At this time, the stack upper limit value is 20001000-1000 = 2000.
It will be address 0000. The calculated stack upper limit value is written in the task control block 5. The same applies when the task B is generated.

【0017】タスクAの起動時に、タスクコントロール
ブロック5からスタック上限値を読み出して、この値が
タスクスタック上限値設定レジスタ1に設定される。
When the task A is started, the stack upper limit value is read from the task control block 5, and this value is set in the task stack upper limit value setting register 1.

【0018】タスクAの実行中に、アドレスマッチング
回路2はスタック上限値設定レジスタ1の値と、アドレ
ス線4上のアドレス値とを比較しており、タスクAのス
タック上限値を越えるスタックアドレスがリード/ライ
トされると、CPU3に割り込みを入れて、スタックオ
ーバーフローが発生したことを知らせる。
During execution of the task A, the address matching circuit 2 compares the value of the stack upper limit value setting register 1 with the address value on the address line 4, and the stack address exceeding the stack upper limit value of the task A is detected. When read / written, the CPU 3 is interrupted to notify that a stack overflow has occurred.

【0019】また、タスクAからタスクBへのタスクス
イッチが発生した場合は、タスクBが起動される時にタ
スクコントロールブロック5からスタック上限値を読み
出して、この値をスタック上限値設定レジスタ1に設定
し直す。
When a task switch from task A to task B occurs, the stack upper limit value is read from task control block 5 when task B is activated, and this value is set in stack upper limit value setting register 1. Do it again.

【0020】タスクBの実行中にも、アドレスマッチイ
ング回路2はスタック上限値設定レジスタ1の値と、ア
ドレス線4上のアドレス値とを比較しており、タスクB
のスタック上限値を越えるスタックアドレスがリード/
ライトされると、CPU3に割り込みを入れて、スタッ
クオーバーフローが発生したことを知らせる。
Even during the execution of task B, the address matching circuit 2 compares the value of the stack upper limit value setting register 1 with the address value on the address line 4, and the task B
Stack address exceeding the stack upper limit value of /
When written, it interrupts the CPU 3 to notify that a stack overflow has occurred.

【0021】なお、割り込みを受けたCPU3は、障害
発生時のタスク名などの障害情報をセーブ後、上位ソフ
トウエアに障害発生通知を行なって、上位ソフトウエア
からの命令待ち状態になる。
The CPU 3, which has received the interrupt, saves the failure information such as the task name at the time of the failure occurrence, notifies the upper software of the failure occurrence, and waits for an instruction from the upper software.

【0022】[0022]

【発明の効果】以上説明したように、本発明は下記のよ
うな効果がある。 (1)スタック上限値を越えたアドレスへのアクセスを
即座に検出できるため、スタック破壊された側のタスク
が起動されてから発生するような異常動作を未然に防げ
る。その理由は、タスクスタックへのアクセスがある
と、アドレスマッチング回路がこのアクセスアドレスと
スタック上限値設定レジスタの設定値を比較して、スタ
ックオーバーフロー時にCPUに割り込みをかけるから
である。 (2)スタック上限値を越えたアクセスを確実に検出で
きるため、ネスティング重畳度では検出できないスタッ
クオーバーフローを検出できる。その理由は、スタック
オーバーフローの判断を、ネスティング重畳度ではなく
スタックアドレスの上限値そのものを使用しているから
である。 (3)タスクスイッチのあるマルチタスクでも同じよう
にスタックオーバーフローを検出できることである。こ
れにより、スタックを破壊された側のタスクが異常動作
を起こすまで分からなかったスタックオーバーフローを
即座に検出できるようになる。その理由は、スタックオ
ーバーフローの判断値をレジスタの書き換えだけで容易
に行えるからである。
As described above, the present invention has the following effects. (1) Since an access to an address exceeding the stack upper limit value can be immediately detected, an abnormal operation that occurs after the task on the side of the stack destruction is activated can be prevented. The reason is that when the task stack is accessed, the address matching circuit compares the access address with the set value of the stack upper limit setting register and interrupts the CPU when the stack overflows. (2) Since the access exceeding the stack upper limit value can be reliably detected, the stack overflow that cannot be detected by the nesting superposition degree can be detected. The reason is that the stack overflow is determined by using the upper limit value of the stack address itself instead of the nesting superposition degree. (3) A stack overflow can be detected in the same way even in a multitask task switch. As a result, it becomes possible to immediately detect a stack overflow that is unknown until the task on the side where the stack is destroyed abnormally operates. The reason is that the judgment value of stack overflow can be easily performed only by rewriting the register.

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

【図1】本発明の一実施例形態を示すブロック図であ
る。
FIG. 1 is a block diagram showing an embodiment of the present invention.

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

1 スタック上限値設定レジスタ 2 アドレスマッチング回路 3 CPU 4 アドレス線 5 タスクコントロールブロック 6 スタック用メモリ領域 1 Stack upper limit setting register 2 Address matching circuit 3 CPU 4 Address line 5 Task control block 6 Stack memory area

Claims (2)

【特許請求の範囲】[Claims] 【請求項1】 各タスクのスタック上限値が設定される
スタック上限値設定レジスタと、アドレス線上のアドレ
ス値を前記スタック上限値設定レジスタに設定されてい
るスタック上限値と比較し、該アドレス値が該スタック
上限値を越えた場合、CPUに割り込みを入れるアドレ
スマッチング回路を有するタスクスタックオーバーフロ
ー検出回路。
1. A stack upper limit value setting register in which a stack upper limit value of each task is set, and an address value on an address line is compared with a stack upper limit value set in the stack upper limit value setting register, and the address value is A task stack overflow detection circuit having an address matching circuit for interrupting the CPU when the stack upper limit is exceeded.
【請求項2】 タスク生成時にタスクスタック量から算
出されたスタック上限値が書き込まれるタスクコントロ
ールブロックをさらに有し、タスク起動時に前記タスク
コントロールブロックからスタック上限値が読み出され
て前記スタック上限値設定レジスタに設定される、請求
項1記載のタスクスタックオーバーフロー検出回路。
2. A task control block to which a stack upper limit value calculated from a task stack amount is written when a task is generated, and the stack upper limit value is read from the task control block when the task is activated, and the stack upper limit value is set. The task stack overflow detection circuit according to claim 1, which is set in a register.
JP734196A 1996-01-19 1996-01-19 Task stack overflow detecting circuit Pending JPH09198258A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
JP734196A JPH09198258A (en) 1996-01-19 1996-01-19 Task stack overflow detecting circuit

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
JP734196A JPH09198258A (en) 1996-01-19 1996-01-19 Task stack overflow detecting circuit

Publications (1)

Publication Number Publication Date
JPH09198258A true JPH09198258A (en) 1997-07-31

Family

ID=11663247

Family Applications (1)

Application Number Title Priority Date Filing Date
JP734196A Pending JPH09198258A (en) 1996-01-19 1996-01-19 Task stack overflow detecting circuit

Country Status (1)

Country Link
JP (1) JPH09198258A (en)

Cited By (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100350484B1 (en) * 1998-11-23 2002-08-28 삼성전자 주식회사 Apparatus and method for detecting corruption associated with a stack in a storage device
JP2008023376A (en) * 2007-10-11 2008-02-07 Sophia Co Ltd Arithmetic processing unit for games
JP2008023375A (en) * 2007-10-11 2008-02-07 Sophia Co Ltd Arithmetic processing unit for games
JP2008023377A (en) * 2007-10-11 2008-02-07 Sophia Co Ltd Arithmetic processing unit for games
US8195885B2 (en) 2006-06-23 2012-06-05 Denso Corporation Electronic unit for saving state of task to be run in stack
JP2015191658A (en) * 2014-03-28 2015-11-02 インテル・コーポレーション Return-target restrictive return instructions from procedure, processors, methods, and systems
US9280500B2 (en) 2007-01-05 2016-03-08 Samsung Electronics Co., Ltd. Method and apparatus for preventing stack overflow in embedded system
CN109144756A (en) * 2017-06-27 2019-01-04 阿里巴巴集团控股有限公司 A kind of method and device of stack overflow processing

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
KR100350484B1 (en) * 1998-11-23 2002-08-28 삼성전자 주식회사 Apparatus and method for detecting corruption associated with a stack in a storage device
US8195885B2 (en) 2006-06-23 2012-06-05 Denso Corporation Electronic unit for saving state of task to be run in stack
US9280500B2 (en) 2007-01-05 2016-03-08 Samsung Electronics Co., Ltd. Method and apparatus for preventing stack overflow in embedded system
JP2008023376A (en) * 2007-10-11 2008-02-07 Sophia Co Ltd Arithmetic processing unit for games
JP2008023375A (en) * 2007-10-11 2008-02-07 Sophia Co Ltd Arithmetic processing unit for games
JP2008023377A (en) * 2007-10-11 2008-02-07 Sophia Co Ltd Arithmetic processing unit for games
JP2015191658A (en) * 2014-03-28 2015-11-02 インテル・コーポレーション Return-target restrictive return instructions from procedure, processors, methods, and systems
US9703948B2 (en) 2014-03-28 2017-07-11 Intel Corporation Return-target restrictive return from procedure instructions, processors, methods, and systems
CN109144756A (en) * 2017-06-27 2019-01-04 阿里巴巴集团控股有限公司 A kind of method and device of stack overflow processing

Similar Documents

Publication Publication Date Title
KR960035263A (en) Multi-program execution control device and method
JP3970609B2 (en) Processor system
JPH09198258A (en) Task stack overflow detecting circuit
US5257269A (en) Error controller for use in debugging microprocessor
JPH02156357A (en) Program destruction preventing method
JP2000020352A (en) Stack overflow detecting method and stack underflow detecting method
JP2000076081A (en) Task manager and program recording medium
JPH05100847A (en) Memory protection system for information processor
JP2000155677A (en) Method for preventing runaway of program and computer system for the method and recording medium for recording program for preventing runaway
JPH02293939A (en) Stack overflow detection time processing system
JPH07210421A (en) Debugging method in thread environment
JPH0844629A (en) Memory access abnormality monitoring device
KR200298474Y1 (en) Program protection device during flash memory update
JP3102381B2 (en) Task debugging device, task debugging method, and recording medium therefor
JPH02245937A (en) Information processor
JP2002082820A (en) Computer system for processor runaway pervention
JPH06202901A (en) Rom emulation system debugger and rom emulation method
JPH02278446A (en) Memory access control circuit
JPH01180656A (en) Memory protecting device
JPH09160800A (en) Emulator
JPH05250275A (en) Error processing system
JPH05307506A (en) Data protecting circuit of controller
JPH05282209A (en) Data access controller
JPH02244345A (en) Information processor
JPH05134929A (en) Data access control system