[PATCH 02/10] microblaze: Fix crt bootstrap

Steven J. Magnani steve at digidescorp.com
Tue Oct 5 14:23:15 UTC 2010


Rework crt bootstrap to work with the new __uClibc_main(),
and hardwire crt init/fini code since the awk approach to generating it on
the fly doesn't work for microblaze.

Signed-off-by: Steven J. Magnani <steve at digidescorp.com>
---
diff -uprN a/libc/sysdeps/linux/microblaze/crt1.S b/libc/sysdeps/linux/microblaze/crt1.S
--- a/libc/sysdeps/linux/microblaze/crt1.S	1969-12-31 18:00:00.000000000 -0600
+++ b/libc/sysdeps/linux/microblaze/crt1.S	2010-09-21 20:10:24.000000000 -0500
@@ -0,0 +1,61 @@
+/*
+ * libc/sysdeps/linux/microblaze/crt1.S -- Initial program entry point for linux/microblaze
+ *
+ *  Copyright (C) 2009       Meyer Sound Laboratories
+ *  Copyright (C) 2003       John Williams <jwilliams at itee.uq.edu.au>
+ *  Copyright (C) 2001,2002  NEC Corporation
+ *  Copyright (C) 2001,2002  Miles Bader <miles at gnu.org>
+ *
+ * This file is subject to the terms and conditions of the GNU Lesser
+ * General Public License.  See the file COPYING.LIB in the main
+ * directory of this archive for more details.
+ *
+ * Written by Miles Bader <miles at gnu.org>
+ */
+
+#include <libc-symbols.h>
+
+/* Upon entry, the stack contains the following data:
+	argc, argv[0], ..., argv[argc-1], 0, envp[0], ..., 0
+*/
+
+	.text
+	.globl C_SYMBOL_NAME(_start)
+	.align 4
+C_SYMBOL_NAME(_start):
+	
+	/* Load SDAs */
+	la	r2, r0, C_SYMBOL_NAME(_SDA2_BASE_) /* in the original source r2 was SDA, and r13 was SDA2, no idea why */
+	la	r13, r0, C_SYMBOL_NAME(_SDA_BASE_)
+
+	/*
+	Preparing arguments for uClibc's startup routine.
+	The routine has 6 arguments, so 5 of them are placed
+	into registers, one on the stack
+	*/
+	
+	la      r5, r0, C_SYMBOL_NAME(main) /* Arg 1: main() */
+	lw	r6, r0, r1		    /* Arg 2: argc   */
+	addi	r7, r1, 4		    /* Arg 3: argv   */
+	la	r8, r0, _init               /* Arg 4: init   */
+	la	r9, r0, _fini               /* Arg 5: fini   */
+	addk	r10,r0,r0                   /* Arg 6: rtld_fini = NULL */
+
+
+	// Reserve space for __uClibc_main to save parameters 
+	// (Microblaze ABI stack calling convention)
+	// and for stack_end argument to __uClibc_main
+	add 	r3, r1, r0
+	addi    r1, r1, -32
+
+	/* tail-call uClibc's startup routine */
+	brid	C_SYMBOL_NAME(__uClibc_main)
+	swi 	r3, r1, 28	/* Arg 7: stack end [DELAY SLOT] */
+
+/* Define a symbol for the first piece of initialized data.  */
+	.data
+	.globl __data_start
+__data_start:
+	.long 0
+	.weak data_start
+	data_start = __data_start
diff -uprN a/libc/sysdeps/linux/microblaze/crti.S b/libc/sysdeps/linux/microblaze/crti.S
--- a/libc/sysdeps/linux/microblaze/crti.S	1969-12-31 18:00:00.000000000 -0600
+++ b/libc/sysdeps/linux/microblaze/crti.S	2010-09-21 20:10:24.000000000 -0500
@@ -0,0 +1,31 @@
+#define END_INIT
+#define END_FINI
+#define ALIGN
+#include <libc-symbols.h>
+
+/*@HEADER_ENDS*/
+	
+	.section .init
+	.align	2
+	.globl	_init
+_init:
+	addik	r1, r1, -32
+	swi	r19, r1, 28
+	addk	r19, r1, r0
+	swi	r15, r1, 0
+
+	
+	ALIGN
+	END_INIT
+	
+	.section .fini
+	.align	2
+	.globl	_fini
+_fini:
+	addik	r1, r1, -32
+	swi	r19, r1, 28
+	addk	r19, r1, r0
+	swi	r15, r1, 0
+
+	ALIGN
+	END_FINI
diff -uprN a/libc/sysdeps/linux/microblaze/crtn.S b/libc/sysdeps/linux/microblaze/crtn.S
--- a/libc/sysdeps/linux/microblaze/crtn.S	1969-12-31 18:00:00.000000000 -0600
+++ b/libc/sysdeps/linux/microblaze/crtn.S	2010-09-21 20:10:24.000000000 -0500
@@ -0,0 +1,34 @@
+#define END_INIT
+#define END_FINI
+#define ALIGN
+#include <libc-symbols.h>
+	
+	.section .init
+	.align	2
+	.globl	_init
+	.ent	_init
+
+	lwi	r15, r1, 0
+	lwi	r19, r1, 28
+	rtsd	r15, 8 
+	addik	r1, r1, 32	# Delay slot
+
+	.end	_init
+$Lfe2:
+	.size	_init,$Lfe2-_init
+	
+	.section .fini
+	.align	2
+	.globl	_fini
+	.ent	_fini
+
+	lwi	r15, r1, 0
+	lwi	r19, r1, 28
+	rtsd	r15, 8 
+	addik	r1, r1, 32	# Delay slot
+
+	.end	_fini
+$Lfe3:
+	.size	_fini,$Lfe3-_fini
+	
+/*@TRAILER_BEGINS*/



More information about the uClibc mailing list