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

📄 __ppc_eabi_init.c

📁 摩托罗拉处理器mpc855上的UCOS移植代码
💻 C
字号:
/***************************************************************************/
/*

FILE
	__ppc_eabi_init.c

DESCRIPTION

	Use this file for C.  Contains calls to initialize memory pools
	for use with malloc/free. 
	
	Interface for board-level initialization and user-level initialization.
	
	If hardware initialization and pre-main user initialization are required,
	copy this file to your project directory and customize it (instead of
	customizing __start.c).
	
	Note that __init_hardware should not write on the stack until the
	memory controller is properly configured.

	
	void __init_hardware(void)
	
		Initialize the hardware, including the memory controller.
	
	void __init_user(void)
	
		Allow the user to perform initialization before calling main().

	void _ExitProcess(void)
 		
 		This function simply stalls the debugger.  You may want to rewrite this
 		function if you are using an OS.
	
 	abort and exit
 
 	In order to correctly implement the required startup/termination sequence for
 	C and C++ programs, we need to have an exit() routine that can be called by
 	the program startup code. The exit() routine is supposed to
 
 		(1)	call any functions registered via atexit()
 		(2) call destructors for any global objects
 		(3)	flush any unwritten buffers, close any open files, etc.
 		(4) terminates the program
 
 	We don't, however, want to require the ANSI C library for every CodeWarrior
 	program, since it drags in lots of code that may not be needed.
 
 	Instead we provide a dummy exit() function which simply calls the destructors
 	and terminates the program. We assume that any program which uses atexit()
 	or <stdio.h> and which requires those cleanup behaviors will have linked with
 	the ANSI C library, whose definition of exit() will override the one here.
 
 	We similarly define a dummy abort() function (which is called by the default
 	terminate() handler).
 
 	Programs which rely on the proper ANSI C/C++ behavior must use the ANSI C
 	library, and order it in the CodeWarrior project or command-line so that
 	its definitions supersede these definitions in the runtime support library.
 
	
COPYRIGHT	
	(c) 1997 Metrowerks Corporation
	All rights reserved.

HISTORY
	97 APR 17 LLY	Created.
	97 JUN 24 MEA	Added support for C++ and malloc memory heaps.
	97 JUN 26 MEA	Made C and C++ versions of this file.  Added abort and exit.
	97 JUL 17 SCM	Customized for MPC821 ADS board.
	97 JUL 20 MEA	Changed __exit to _ExitProcess so as not to conflict with MSL.
					_ExitProcess added to this file; removed form __start.c.

*/
/***************************************************************************/

#include <__ppc_eabi_init.h>
#include <__ppc_eabi_linker.h>		/* linker-generated symbol declarations */
#include <pool_alloc.h>
#include <stdlib.h>

extern void inithw(void);


asm void __init_hardware(void)
{
	/*
	 *	Initialize Motorola ADS board unless running with MWDebug.
	 *	Uncomment the initialization below if running with MPC8BUG
	 *	or standalone.  You may need to perform other initializations.
	 */
	nofralloc

   /*
	* If we are using Hardware  floating point we need to make sure
 	* to enable the FP bit in the  MSR
 	*/	

#if __option(floatingpoint)==1 &&  __option(sfp_emulation)==0
 	mfmsr r0
 	ori  r0,r0,0x00002000
 	mtmsr r0
#endif	

	/*
	 *	When customizing, be aware that the memory controller may not be
	 *	configured.
	 */
	lis     r0,0xFFF0 			/* IMMR */
	ori     r0,r0,0x800
	mtspr	638,r0

	li      r0,0x0000			/* BBCMCR */
	mtspr	560,r0

	mflr	r31						/* save off return address in NV reg */
	bl		inithw 				/* init board hardware */

	mtlr	r31						/* get saved return address */

	blr
}

static void AllocMoreHeap(void)
{
	/*
	 *	By default, we use MSL's allocation (malloc/free) even with C++.
	 *	If you have declared a heap size in the Project Pref panel,
	 *	a defaull heap will be created the first time you call
	 *	malloc.  You can add more calls to init_alloc to create additional
	 *	heaps.
	 */
/*	init_alloc(some address, some size); */
}


asm void __init_user(void)
{
	fralloc
	/*
	 *	Allocate additional heaps.
	 */
/*	bl		AllocMoreHeaps */
	frfree
	blr
}

#pragma overload void abort(void);
void abort(void)
{
	_ExitProcess();
}


#pragma overload void exit(int status);
void exit(int status)
{
	#pragma unused(status)
	_ExitProcess();
}


/*
 *	_ExitProcess
 *
 *	PowerPC EABI Runtime termination
 */
asm void _ExitProcess(void)
{
	nofralloc
	
	tw		31,r3,r4					/* arbitrary break trap for halt */
}

⌨️ 快捷键说明

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