⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nios_setjmp.s

📁 ALTERA的NIOS处理器!文件直接可以打开直接选择器件重新编译!
💻 S
字号:
;
; Nios implementation of setjmp
;
; Note that you must include "nios.h"
; (or "nios.s") to get this routine,
; rather than <setjmp.h>.
;
; setjmp() and longjmp() are both
; included here. If you use one, you'll
; most likely want both. Yeah.
;

	.include "nios.s"
	.text

;----------------------------------------
;         Name: nr_setjmp
;  Description: Save the current context so
;               a nr_longjmp works later.
;        Input: %o0: jmp_buf: (ptr to) array to store context in
;       Output: %o0 = 0 the first time we're called, or
;               whatever longjmp returns later
; Side Effects: 
;    CWP Depth: 0
;

	.global	nr_setjmp
nr_setjmp:
	ST	[%o0],%i7	; present return address
	PFX	1
	ST	[%o0],%o7	; where the longjmp will later execute from
	JMP	%o7
	MOVI	%o0,0		; (delay slot) return value is zero


;----------------------------------------
;         Name: nr_longjmp
;  Description: Restore the current context
;               as saved by a previous nr_setjmp
;        Input: %o0: jmp_buf (ptr to) array to restore context from
;               %o1: integer to return
;       Output: %o0 = 0 the first time we're called, or
;               whatever longjmp returns later
; Side Effects: uses %g0, %g1 & %g2
;    CWP Depth: 0
;

	.global	nr_longjmp
nr_longjmp:
	;
	; The way we'll do this is by executing
	; RESTORE instructions until the old
	; return address matches. Then we'll
	; jump to where setjmp was called from.
	;
	; Since we're moving the window pointer
	; all over the place, we'll naturally
	; only use the %g registers.
	;

	MOV	%g0,%o0		; %g0 -> jmp_buf
	MOV	%g1,%o1		; %g1 = return value
	LD	%g2,[%g0]	; %g2 = old return address
nr_longjmp_loop:
	CMP	%g2,%i7		; Are we there yet?
	IFS	cc_eq
	 BR	nr_longjmp_done
	 NOP			; (delay slot)

	BR	nr_longjmp_loop
	RESTORE			; (delay slot)
	;
	; One might put in a watchdog counter here, to
	; prevent a runaway stack crawl... but what would that
	; accomplish? What error can we throw? To whom?
	;

nr_longjmp_done:
	PFX	1
	LD	%o7,[%g0]	; set fake return address
	JMP	%o7		; and kinda return there.
	MOV	%o0,%g1		; (delay slot) return value

; end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -