* [PATCH 05/15] [nds32] Refine _start in crt0.S and crt1.S
@ 2014-03-20 3:10 Hui-Wen Ni
0 siblings, 0 replies; only message in thread
From: Hui-Wen Ni @ 2014-03-20 3:10 UTC (permalink / raw)
To: newlib
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: 0005-nds32-Refine-_start-in-crt0.S-and-crt1.s.patch --]
[-- Type: application/octet-stream, Size: 5834 bytes --]
From 87ec62a145fd6ab3cf52a4b4f8b9d547446f4687 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito@andestech.com>
Date: Mon, 7 Oct 2013 10:08:32 +0800
Subject: [PATCH 05/15] [nds32] Refine _start in crt0.S and crt1.s
* libgloss/nds32/crt0.S: Refine.
* libgloss/nds32/crt1.S: Refine.
---
libgloss/nds32/crt0.S | 56 +++++++++++++++++++++++----------------------------
libgloss/nds32/crt1.S | 52 +++++++++++++++++++++--------------------------
2 files changed, 48 insertions(+), 60 deletions(-)
diff --git a/libgloss/nds32/crt0.S b/libgloss/nds32/crt0.S
index 97c02c5..5ee9272 100644
--- a/libgloss/nds32/crt0.S
+++ b/libgloss/nds32/crt0.S
@@ -36,7 +36,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
##==============================================================================
-
##------------------------------------------------------------------------------
## Vector table setup
##------------------------------------------------------------------------------
@@ -53,53 +52,48 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.type _start, @function
.align 2
_start:
-.L_fp_gp_lp_init:
- /* Initialization for $fp, $gp, and $lp. The _SDA_BASE_ location
+.L_fp_gp_init:
+ /* Initialization for $fp and $gp. The _SDA_BASE_ location
stands for Small Data Access. */
la $fp, _FP_BASE_
la $gp, _SDA_BASE_
- movi $lp, #0
.L_stack_init:
/* Initialization for $sp and make sure it is 8-byte aligned. */
la $sp, _stack
+#if __NDS32_ISA_V3__
+ bitci $sp, $sp, #7
+#else
movi $r0, #-8 /* Set $r0 as 0xFFFFFFF8. */
and $sp, $sp, $r0
+#endif
.L_bss_clear:
- /* Clear bss section. */
- la $r3, _end
- la $r0, _edata
- beq $r0, $r3, .L_call_main /* Branch if no bss. */
- sub $r1, $r3, $r0 /* Size to be clear. */
-
- /* Set $r2 as how many words to be clear.
- Set $r1 as how many bytes are less than a woard to be clear. */
- srli $r2, $r1, #2
- andi $r1, $r1, #3
- beqz $r3, .Lbyte_clear
-
- la $r4, #0x00000000
+ /* Clear bss section.
+ Equivalence C code for follow part:
+ if (_end == _edata) goto .L_call_main
+ unsinged int *ptr = _edata;
+ while (ptr != _end)
+ *ptr++ = 0
+ $r0 = ptr/_edata
+ $r1 = _end
+ $r2 = 0
+ */
+ la $r0, _edata
+ la $r1, _end
+ movi $r2, #0
+ beq $r0, $r1, .L_call_main /* Branch if no bss. */
.Lword_clear:
- swi.bi $r4, [$r0], #4
- addi $r2, $r2, #-1
- bnez $r2, .Lword_clear /* Loop again ? */
- beqz $r1, .Lend_bss
-
-.Lbyte_clear:
- sbi.bi $r4, [$r0], #1
- addi $r1, $r1, #-1
- bnez $r1, .Lbyte_clear
-.Lend_bss:
-
+ swi.bi $r2, [$r0], #4
+ bne $r0, $r1, .Lword_clear
.L_call_main:
/* Prepare argc/argv/env for main function.
Since there is no operating system so far,
- we set $r0, $r1, and $r2 to be zero. */
+ we set $r0, $r1, and $r2 to be zero.
+ Note: $r2 already set to zero in line 84. */
movi $r0, 0
movi $r1, 0
- movi $r2, 0
/* Call 'main'. */
la $r15, main
jral $r15
@@ -118,6 +112,6 @@ _start:
.L_forever_loop:
/* Should never return here. */
- b .L_forever_loop
+ b .L_forever_loop
.size _start, .-_start
diff --git a/libgloss/nds32/crt1.S b/libgloss/nds32/crt1.S
index 60c18c3..1d83433 100644
--- a/libgloss/nds32/crt1.S
+++ b/libgloss/nds32/crt1.S
@@ -36,7 +36,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
##==============================================================================
-
##------------------------------------------------------------------------------
## Vector table setup
##------------------------------------------------------------------------------
@@ -53,45 +52,40 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.type _start, @function
.align 2
_start:
-.L_fp_gp_lp_init:
- /* Initialization for $fp, $gp, and $lp. The _SDA_BASE_ location
+.L_fp_gp_init:
+ /* Initialization for $fp and $gp. The _SDA_BASE_ location
stands for Small Data Access. */
la $fp, _FP_BASE_
la $gp, _SDA_BASE_
- movi $lp, #0
.L_stack_init:
/* Initialization for $sp and make sure it is 8-byte aligned. */
la $sp, _stack
+#if __NDS32_ISA_V3__
+ bitci $sp, $sp, #7
+#else
movi $r0, #-8 /* Set $r0 as 0xFFFFFFF8. */
and $sp, $sp, $r0
+#endif
.L_bss_clear:
- /* Clear bss section. */
- la $r3, _end
- la $r0, _edata
- beq $r0, $r3, .L_call_main /* Branch if no bss. */
- sub $r1, $r3, $r0 /* Size to be clear. */
-
- /* Set $r2 as how many words to be clear.
- Set $r1 as how many bytes are less than a woard to be clear. */
- srli $r2, $r1, #2
- andi $r1, $r1, #3
- beqz $r3, .Lbyte_clear
-
- la $r4, #0x00000000
+ /* Clear bss section.
+ Equivalence C code for follow part:
+ if (_end == _edata) goto .L_call_main
+ unsinged int *ptr = _edata;
+ while (ptr != _end)
+ *ptr++ = 0
+ $r0 = ptr/_edata
+ $r1 = _end
+ $r2 = 0
+ */
+ la $r0, _edata
+ la $r1, _end
+ beq $r0, $r1, .L_call_main /* Branch if no bss. */
+ movi $r2, #0
.Lword_clear:
- swi.bi $r4, [$r0], #4
- addi $r2, $r2, #-1
- bnez $r2, .Lword_clear /* Loop again ? */
- beqz $r1, .Lend_bss
-
-.Lbyte_clear:
- sbi.bi $r4, [$r0], #1
- addi $r1, $r1, #-1
- bnez $r1, .Lbyte_clear
-.Lend_bss:
-
+ swi.bi $r2, [$r0], #4
+ bne $r0, $r1, .Lword_clear
.L_call_main:
/* Call '_init' to invoke constructors. */
@@ -124,6 +118,6 @@ _start:
.L_forever_loop:
/* Should never return here. */
- b .L_forever_loop
+ b .L_forever_loop
.size _start, .-_start
--
1.9.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-03-20 3:10 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-20 3:10 [PATCH 05/15] [nds32] Refine _start in crt0.S and crt1.S Hui-Wen Ni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).