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

📄 vrtlib16.s

📁 VRTX操作系统
💻 S
📖 第 1 页 / 共 3 页
字号:
;*************************************************************************
;
;
;  IMPORTANT - USE OF THIS SOFTWARE IS SUBJECT TO LICENSE RESTRICTIONS
;  CAREFULLY READ THE LICENSE AGREEMENT BEFORE USING THE SOFTWARE
;
;
;*************************************************************************
; Issue: 0.03/23-Feb-93
;
; Purpose: Minimal, standalone, VRTXmc library kernel Mixed ARM/Thumb
;
; Copyright (C) 1993 Advanced RISC Machines Limited. All rights reserved.
;
; Advanced RISC Machines Limited does not assume any liability arising out
; of this program or use thereof neither does it convey any licence under
; its intellectual property rights.
;
; Conditions of use:
;
; The terms and conditions under which this software is supplied to you and
; under which you may use it are described in your licence agreement with
; your supplier.
;
;----------------------------------------------------------------------------;
; ABOUT THIS CODE                                                            ;
;                                                                            ;
; This code depends hardly at all on its target environment and is  ;
; designed to be very easy to adapt to your particular ARM-based system.     ;
; You can expect it to take about a couple of hours to re-target.            ;
;                                                                            ;
; Much of the code below is generic to the ARM processor and is completely   ;
; independent of your ARM-based hardware or any operating system kernel that ;
; may run on it.                                                             ;
;                                                                            ;
; WHAT THIS CODE PROVIDES:                                                   ;
;                                                                            ;
;      - program termination (__rt_exit)                                     ;
;      - determining FP instruction-set availability (__rt_fpavailable)      ;
;                                                                            ;
;  - Functions to help with heap allocation, stack-limit checking, setjmp    ;
;    and longjmp. These may need to be customised for your environment,      ;
;    but can almost certainly be used as-is in a first re-targetting.        ;
;                                                                            ;
;  - Fully 'rolled' divide (and remainder) functions.                        ;
;                                                                            ;
; WHAT THIS CODE DOES NOT PROVIDE                                            ;
;                                                                            ;
;  - Support for exceptions or interrupts.                                   ;
;                                                                            ;
;  - A way to print to the debugging channel (use in line SWIs)              ;
;                                                                            ;
;----------------------------------------------------------------------------;
; Revisions of VRTLIB16.S
; 1.0  P.Cumming  25/04/96  ARM & Thumb RTSTAND.S  
;                           adapted by Samsung & P.Cumming for VRTXmc 

DefaultStackIncrement EQU  0     ; At each overflow it grows by at
                                 ; at least this many bytes.
				 ;defaults to 0 for VRTmc stack size is fixed
				 ;at configuration time in vmcconf.c

StackSlop             EQU  256        ; sl is kept this far above the real
                                      ; stack low-water mark. NOTE: MUST be
                                      ; = 256 for VRTXmc
  GBLL EnsureNoFPSupport
EnsureNoFPSupport     SETL {TRUE}     ; If {TRUE} then the availability of
                                      ; Floating Point Support is ignored.
                                      ; If {FALSE} then FP availability is
                                      ; checked for.
                                      ; Setting to {TRUE} saves a little
                                      ; space.

        IMPORT  |__err_handler|, WEAK
	IMPORT	|vmc_write|, WEAK
	IMPORT	|user_exit|, WEAK
	IMPORT	|cpu_interrupt_disable|
	

;----------------------------------------------------------------------------;
; Now the symbols we define and EXPORT from this this module.                ;
;----------------------------------------------------------------------------;

        EXPORT  |__rt_exit|
	EXPORT	|__rt_exit16|
        EXPORT  |__rt_fpavailable|
        EXPORT  |__rt_trap|
	EXPORT	|__rt_trap16|

;----------------------------------------------------------------------------;
; Next, optional support for C stack-limit checking. This code should need   ;
; no attention in a first re-targetting.                                     ;
;----------------------------------------------------------------------------;

        EXPORT  |__rt_stkovf_split_small| ; veneer
        EXPORT  |__rt_stkovf_split_big|
	EXPORT  |__16__rt_stkovf_split_small| ; veneer
        EXPORT  |__16__rt_stkovf_split_big|


;----------------------------------------------------------------------------;
; Then two C-specific functions which should require no attention in a first ;
; re-targetting. Note that they depend on __rt_fpavailable.                  ;
;----------------------------------------------------------------------------;

        EXPORT  |setjmp|
        EXPORT  |longjmp|

;----------------------------------------------------------------------------;
; And, finally, generic ARM functions, referred to by the C compiler.        ;
; You should not need to alter any of these unless you wish to incorporate   ;
; them in your operating system kernel. See also later comments.             ;
;----------------------------------------------------------------------------;

        EXPORT  |__rt_udiv|
        EXPORT  |__rt_udiv10|
        EXPORT  |__rt_sdiv|
        EXPORT  |__rt_sdiv10|
        EXPORT  |__rt_divtest|
	EXPORT  |__16__rt_udiv|
        EXPORT  |__16__rt_udiv10|
        EXPORT  |__16__rt_sdiv|    
        EXPORT  |__16__rt_sdiv10|      
        EXPORT  |__16__rt_divtest|

	EXPORT	|__rt_halt|
	
	MACRO
        RET
        BX      lr
        MEND

; Used for ARM/Thumb interwork calls via function pointers
        EXPORT  |__call_via_r0|
        EXPORT  |__call_via_r1|
        EXPORT  |__call_via_r2|
        EXPORT  |__call_via_r3|

	
	CODE32
;----------------------------------------------------------------------------;
        AREA    |C$$code$$__call_via|, CODE, READONLY, INTERWORK                              ;
;----------------------------------------------------------------------------;


|__call_via_r0|
        BX r0

|__call_via_r1|
        BX r1

|__call_via_r2|
        BX r2

|__call_via_r3|
        BX r3

;----------------------------------------------------------------------------;
      AREA    |C$$code$$__rt_stkovf|, CODE, READONLY	                     ;
; The code area containing __rt_stkovf_*                                     ;
;----------------------------------------------------------------------------;
; C stack-limit checking support.                                            ;
;                                                                            ;
; NOTES                                                                      ;
;                                                                            ;
; 1/ Stack-limit-checking is optional                                        ;  
;    However, the cost of the check is (very) small and the value sometimes  ;
;    considerable.                                                           ;
;                                                                            ;
; 2/ In VRTXmc a call to __rt_stkovf_split is fatal                          ;
;    This is because the stack size is fixed in vmcconf.c.                   ;
;    The usable stack size is stack size - stack slop                        ;
;    Stackslop acts as a safety margin for the compiler stack checking       ;                                        ;
;    limits and to provide some stack to handle a stack overflow             ;
;----------------------------------------------------------------------------;

|__rt_stkovf_split_small|                         ; stkovf_split_small_frame ;
;
; Enter here when a C function with frame size <= 256 bytes underflows
; the stack low-water mark + StackSlop (sl). Falls into the big-frame case.

; fall into big-frame case with size of 0.

|__rt_stkovf_split_big|                             ; stkovf_split_big_frame ;
;
; Enter here when a C function with frame size > 256 bytes would underflow
; the stack low-water mark + StackSlop (sl). No stack space has been claimed

        MOV   ip, #DefaultStackIncrement      ; the default increment

        SUB     r10, r10, ip
        SUB     r10, r10, #StackSlop            ; new stack low-water mark
						; ok for error handling
        ADR     ip, StackOverflowError
	MOV	a3,#StackOverflowErrorLen	;length of stack overflow error message
        B       save_regs_and_trap

StackOverflowErrorLen	EQU	15
StackOverflowError
        DCD     3
        DCB     "stack overflow", 0
        ALIGN

;----------------------------------------------------------------------------;
       AREA    |C$$code$$__rt_halt|, CODE, READONLY, INTERWORK						 ;
; The code area containing __rt_halt                                         ;
;----------------------------------------------------------------------------;
; Support for low-level failures - halt handler                              ;
;----------------------------------------------------------------------------;

|__rt_halt|
;
; void __rt_halt(void);
        ADR     ip, VRTXmcPanicError
	MOV	a3,#VRTXmcPanicErrorLen
        B       save_regs_and_trap

VRTXmcPanicErrorLen	EQU	13
VRTXmcPanicError
        DCD     4
        DCB     "VRTXmc panic", 0
        ALIGN

;----------------------------------------------------------------------------;
       AREA    |C$$code$$__rt_trap|, CODE, READONLY, INTERWORK
; The code area containing __rt_trap                                         ;
;----------------------------------------------------------------------------;
; Support for low-level failures - currently stack overflow, divide by 0 and ;
; floating-point exceptions. If there is a higher level handler, call it;    ;
; otherwise, print a message and exit gracefully.                            ;
;                                                                            ;
; NOTES                                                                      ;
;                                                                            ;
; typedef struct { unsigned code; char message[252];} __rt_error;            ;
; typedef struct { unsigned r[16];} __rt_registers;                          ;
;                                                                            ;
;----------------------------------------------------------------------------;

|__rt_trap|
;
; void __rt_trap(__rt_error *e, __rt_registers *r,int error_text_len);
	STMFD   sp!, {a1,a3}             ; save e in case handler returns...
	BL	cpu_interrupt_disable
        LDR     ip, err_handler
        CMP     ip, #0
        MOVNE   lr, pc   
        MOVNE   pc, ip                ; if got a handler, use it and
        LDMFD   sp!, {v1,v2}          ; hope not to return...

        ADR     a1, RTErrorHead
	MOV	a2,#RTErrorHeadLen	;length of run time error
	LDR	r3,=vmc_write
	CMP	r3,#0			;check if vmc_write BSP present
	BEQ	%F1
	BL	__call_via_r3
        ADD     a1, v1, #4
	MOV	a2,v2				;error text length
	LDR	r3,=vmc_write		;last vmc_write may corrupt r3 so reload
	BL	__call_via_r3
        ADR     a1, RTErrorTail
	MOV	a2,#RTErrorTailLen	;length of program terminated text
	LDR	r3,=vmc_write		;last vmc_write may corrupt r3 so reload
	BL	__call_via_r3
1       
	MOV     a1, #255
        B       |__rt_exit|           ; and terminate with non-zero exit code
err_handler
        DCD     |__err_handler|

save_regs_and_trap
	BL	cpu_interrupt_disable
        STMFD   sp!, {sp, lr, pc}
        STMFD   sp!, {r0-r12}
        STR     lr, [sp, #4*15]       ; caller's pc is my lr
        MOV     a2, sp
        MOV     a1, ip
        B       |__rt_trap|

RTErrorHeadLen	EQU	18
RTErrorHead
        DCB     10, 13, "run time error: ", 0

RTErrorTailLen	EQU	24
RTErrorTail
        DCB     10, 13, "program terminated", 10, 13, 10, 13, 0

        ALIGN


;----------------------------------------------------------------------------;
        AREA    |C$$code$$__exit|, CODE, READONLY, INTERWORK
; The code area containing __rt_exit                                 ;
;----------------------------------------------------------------------------;


|__rt_exit|                                ; exit
;
; void __rt_exit(int code);
; Terminate execution, optionally setting return code (ignored here).
; MUST NOT RETURN.

⌨️ 快捷键说明

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