xref: /nrf52832-nimble/rt-thread/libcpu/mips/loongson_1b/start_gcc.S (revision 104654410c56c573564690304ae786df310c91fc)
1/*
2 * File      : start_gcc.S
3 * This file is part of RT-Thread RTOS
4 * COPYRIGHT (C) 2006 - 2011, RT-Thread Development Team
5 *
6 * The license and distribution terms for this file may be
7 * found in the file LICENSE in this distribution or at
8 * http://www.rt-thread.org/license/LICENSE
9 *
10 * Change Logs:
11 * Date           Author       Notes
12 * 2010-05-17     swkyer       first version
13 * 2010-09-04     bernard      porting to Jz47xx
14 */
15
16#include "../common/mips.inc"
17#include "../common/stackframe.h"
18
19	.section ".start", "ax"
20	.set noreorder
21
22	/* the program entry */
23	.globl  _start
24_start:
25	.set	noreorder
26	la	ra, _start
27
28	/* disable interrupt */
29	mfc0	t0, CP0_STATUS
30	and 	t0, 0xfffffffe	# By default it will be disabled.
31	mtc0	t0, CP0_STATUS	# Set CPU to disable interrupt.
32	nop
33
34	/* disable cache */
35	mfc0	t0, CP0_CONFIG
36	and	t0, 0xfffffff8
37	or	t0, 0x2		# disable,!default value is not it!
38	mtc0	t0, CP0_CONFIG	# Set CPU to disable cache.
39	nop
40
41	/* setup stack pointer */
42	li	sp, SYSTEM_STACK
43	la	gp, _gp
44
45	/* clear bss */
46	la	t0, __bss_start
47	la	t1, __bss_end
48_clr_bss_loop:
49	sw	zero, 0(t0)
50	bne	t0, t1, _clr_bss_loop
51	addiu	t0, t0, 4
52
53	/* jump to RT-Thread RTOS */
54	jal	rtthread_startup
55	nop
56
57	/* restart, never die */
58	j	_start
59	nop
60	.set	reorder
61
62	.globl  cp0_get_cause
63cp0_get_cause:
64	mfc0	v0, CP0_CAUSE
65	jr	ra
66	nop
67
68	.globl  cp0_get_status
69cp0_get_status:
70	mfc0	v0, CP0_STATUS
71	jr	ra
72	nop
73
74	.globl	cp0_get_hi
75cp0_get_hi:
76	mfhi	v0
77	jr	ra
78	nop
79
80	.globl	cp0_get_lo
81cp0_get_lo:
82	mflo	v0
83	jr	ra
84	nop
85
86	.extern tlb_refill_handler
87	.extern cache_error_handler
88
89	/* Exception Handler */
90
91	/* 0x0 - TLB refill handler */
92	.section .vectors.1, "ax", %progbits
93	.global tlb_refill_exception
94	.type	tlb_refill_exception,@function
95tlb_refill_exception:
96	j	tlb_refill_handler
97	nop
98
99	/* 0x100 - Cache error handler */
100	.section .vectors.2, "ax", %progbits
101	j	cache_error_handler
102	nop
103
104	/* 0x180 - Exception/Interrupt handler */
105	.section .vectors.3, "ax", %progbits
106	.global general_exception
107	.type	general_exception,@function
108general_exception:
109	j	_general_exception_handler
110	nop
111
112	/* 0x200 - Special Exception Interrupt handler (when IV is set in CP0_CAUSE) */
113	.section .vectors.4, "ax", %progbits
114	.global irq_exception
115	.type	irq_exception,@function
116irq_exception:
117	j	_irq_handler
118	nop
119
120	.section .vectors, "ax", %progbits
121	.extern mips_irq_handle
122
123	/* general exception handler */
124_general_exception_handler:
125	.set	noreorder
126	la	k0, mips_irq_handle
127	jr	k0
128	nop
129	.set	reorder
130
131	/* interrupt handler */
132_irq_handler:
133	.set	noreorder
134	la	k0, mips_irq_handle
135	jr	k0
136	nop
137	.set	reorder
138