This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: hal_copy_data and hal_zero_bss


Jonathan Larmour wrote:
> 
> Chris Morrow wrote:
> >
> > The hal_copy_data() and hal_zero_bss() in the mips architecture
> > currently
> > do byte reads and writes. Is there any reason they shouldn't use the
> > memset() and memcpy() functions from infra?
> 
> There's no guarantee that calling memcpy and memset won't reference
> different versions of those functions that rely on the BSS being zeroed or
> there being initialized data. e.g. in a debug build.
> 
> Better to write those to do word accesses, taking into account that the
> symbols may not be word-aligned. They should, but they may not be and we
> shouldn't explode if they aren't.
> 
> It would probably be even better to just code them in assembler anyway, and
> avoid the call from vectors.S. It's easy to write a Duff's device
> implementation in asm too. Patches welcome :).
> 
> Jifl
> --
> Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
> Un cheval, pas du glue. Pas du cheval, beaucoup du glue. || Opinions==mine

An assembler version of hal_zero_bss is included
at the end of this message. I placed mine in
vectors.S. I'm not sure where you would like it.

Currently the start up code calls hal_copy_data before
hal_zero_bss. Since at this point the stack is in bss
when calling hal_zero_bss, I can understand why hal_zero_bss
needs to avoid memset(). If the order of calls to mem_copy_data
and hal_zero_bss were switched, what would prevent the use
of memcpy in hal_copy_data? I can't think of any initialized
data memcpy would depend on.

##-----------------------------------------------------------------------------
## hal_zero_bss
## Zero bss. Done is assembler to avoid problem of zeroing
## bss while using it.
FUNC_START(hal_zero_bss)
#ifdef CYGHWR_HAL_MIPS_64BIT
#define STORE_OP	sd
#define BLOCK_SHIFT	6
#else
#define STORE_OP	sw
#define BLOCK_SHIFT	5
#endif
	la	a0,__bss_start		# start of bss
	la	a1,__bss_end		# end of bss
	andi	a2,a0,mips_regsize-1	# is bss aligned?
	bne	a2,zero,1f		# skip word copy
	nop
	
	# loop with 8 stores per loop
	subu		a3,a1,a0		# get length
	srl		a3,a3,BLOCK_SHIFT	# get number of blocks
	sll		a3,a3,BLOCK_SHIFT	# get length of blocks
	addu		a3,a0,a3		# get end addr of blocks
2:	STORE_OP	zero,(mips_regsize*0)(a0)
	STORE_OP	zero,(mips_regsize*1)(a0)
	STORE_OP	zero,(mips_regsize*2)(a0)
	STORE_OP	zero,(mips_regsize*3)(a0)
	STORE_OP	zero,(mips_regsize*4)(a0)
	STORE_OP	zero,(mips_regsize*5)(a0)
	STORE_OP	zero,(mips_regsize*6)(a0)
	STORE_OP	zero,(mips_regsize*7)(a0)
	addu		a0,a0,mips_regsize*8	# next addr
	bne		a3,a0,2b		# to next store
	nop

	# finish 1 byte at a time
1:	sb	zero,0(a0)		# zero memory
	addiu	a0,a0,1			# next addr
	bne	a0,a1,1b		# to next store
	nop
	jr	ra
FUNC_END(hal_zero_bss)

-- 
Chris Morrow	YottaYotta Inc.
email:		cmorrow@yottayotta.com
phone:		(780) 439 9000 ext 227
web:		http://www.yottayotta.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]