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

📄 nios_cstubs.s

📁 ALTERA的NIOS处理器!文件直接可以打开直接选择器件重新编译!
💻 S
字号:

; -------------------------------------
; These routines are the minimal
; set of routines to support
; the C standard libraries and
; printf, which squirts out
; the serial port.
;

		.include "nios_macros.s"


	.text
	.global _sbrk
	.global isatty
	.global _lseek
	.global _close
	.global _fstat
	.global _getpid
	.global _kill
	.global _read
	.global write
	.global _write
	.global _exit
	.global exit

; --------------------------
; exit: just pretend we finished from "main".

exit:
_exit:
	_BR	_past_main
	RESTORE		; (delay slot) well, if the did exit() from main, this'll be right again...

; ---------------------------
; _sbrk
; Returns a new block of ram, and bumps
; the bottom-pointer up a bit.
;

_sbrk:
	SAVE	%sp,-23

	MOVIA	%l0,RAMLimit	; %l0 -> RAM Limit

	LD	%l1,[%l0]	; %l1 = RAM Limit
	LD	%l2,[%l0]	; %l2 = Old RAM Limit

	ADD	%l1,%i0		; Add requested new amount

	ADDI	%l1,3		; round low 2 bits upwards
	ANDNIP	%l1,3

	;
	; See if we're near top of RAM...
	;
	MOV	%l3,%sp
	SUBIP	%l3,256		; safety margin...
	CMP	%l3,%l1
	IFS	cc_gt		; stack > sbrk + block size?
	 BR	sbrk_stillRoom	;  then, good! plenty of room.

	;
	; If we get here, we're out of RAM.
	;
	MOVI	%i0,0		; (branch delay slot, too)
	JMP	%i7
	RESTORE

sbrk_stillRoom:
	ST	[%l0],%l1

sbrk_done:
	MOV	%i0,%l2		; return previous break point
	JMP	%i7
	RESTORE



; ---------------------------
; isatty
; Returns "true": we are hooked up
; to a tty.
isatty:
	JMP	%o7		; that wasn't so bad!
	MOVI	%o0,1

; ---------------------------
; _lseek
; Returns error: serial port unseekable
; to a tty.
_lseek:
	MOVI	%o0,1
	JMP	%o7		; that wasn't so bad!
	NEG	%o0

; ----------------------------
; _close
; _fstat
; _getpid	used by c++
; _kill		used by c++
; Do nothing, and return no error!
;
_close:
_fstat:
_getpid:
_kill:
	JMP	%o7
	MOVI	%o0,0

; ----------------------------
; _read (fd, buf, nbytes)
; Get nBytes into buf.
; We'll ignore fd: serial port only
;
; Oddly enough, we'll only return
; one byte, ever. (getchar doesn't
; get individual keystrokes otherwise.)
; dvb 2000 oct
;
_read:
	SAVE	%sp,-23

read_waitForChar:
	_BSR	nr_uart_rxchar
	MOVI	%o0,0		; (branch delay slot)

	SKPS	cc_pl
	BR	read_waitForChar
	NOP

	_BSR	nr_uart_txchar	; echo character
	MOVI	%o1,0		; (branch delay slot)

	FILL8	%r0,%o0
	ST8D	[%i1],%r0	; store char to buffer

	MOVI	%i0,1		; return "1": how many chars we got.
	JMP	%i7
	RESTORE

; ----------------------------
; _write (fd, buf, nbytes)
; Put nBytes from buf.
; We'll ignore fd: serial port only
;
write:
_write:
	SAVE	%sp,-23
	MOV	%l1,%i1		; %g1 = pointer to buffer to fill
	MOV	%l2,%i2		; %g2 = number of chars still to get
write_nextChar:
	SKPRnz	%l2
	BR	write_gotAllChars

	SUBI	%l2,1		; delay slot

	LD	%o0,[%l1]	; get word containing next character
	EXT8d	%o0,%l1		; extract correct byte for character

	MOVI	%o1,0		; (use default uart)
	_BSR	nr_uart_txchar
		
	ADDI	%l1,1		; delay slot
	BR	write_nextChar
write_gotAllChars:
	MOV	%i0,%i2		; return number of chars put out
	JMP	%i7
	RESTORE



; end of file

⌨️ 快捷键说明

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