kernel/eka/nkernsmp/arm/nk_entry.cia
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32\nkernsmp\arm\nk_entry.cia
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32cia.h>
       
    19 #include <arm.h>
       
    20 #include "nk_priv.h"
       
    21 
       
    22 #include "entry.h"
       
    23 
       
    24 #ifndef	EKA2_ENTRY_POINT_VERSION_IDENTIFIER
       
    25 #define	EKA2_ENTRY_POINT_VERSION_IDENTIFIER	\
       
    26 	asm("tst pc, #%a0" : : "i" ((TInt)0) )
       
    27 #endif
       
    28 
       
    29 extern "C" {
       
    30 
       
    31 extern void HwInit0();
       
    32 extern void KernelMain();
       
    33 extern TLinAddr RomHeaderAddress;
       
    34 extern TLinAddr SuperPageAddress;
       
    35 
       
    36 /*
       
    37  * The main startup program
       
    38  * aRomHeader is address of ROM header passed in by bootstrap
       
    39  * aSuperPage is address of super page passed in by bootstrap
       
    40  *
       
    41  * *** NOTE ***
       
    42  * This is written in assembler in order that nk_exe.lib can be built entirely
       
    43  * from one source file. This is necessary to ensure that the vector table above
       
    44  * appears at the very beginning of the ekern.exe code section.
       
    45  * ************
       
    46  */
       
    47 #if defined(__GCC32__)
       
    48 GLDEF_C __NAKED__ void _E32Startup(TLinAddr /*aRomHeader*/, TLinAddr /*aSuperPage*/)
       
    49 	{
       
    50 	EKA2_ENTRY_POINT_VERSION_IDENTIFIER;	// DUMMY INSTRUCTION TO INDICATE EKA2 ENTRY POINT
       
    51 	asm("ldr r2, __RomHeaderAddress ");
       
    52 	asm("b 1f ");				// branch over space for unique ID
       
    53 
       
    54 	asm(".word 0 ");			// loader will replace with code seg unique ID
       
    55 								// for RAM-loaded code segment
       
    56 								// MUST BE AT OFFSET 12 FROM ENTRY POINT
       
    57 
       
    58 	asm("1: ");
       
    59 	asm("ldr r3, __SuperPage ");
       
    60 	asm("str r0, [r2] ");
       
    61 	asm("str r1, [r3] ");
       
    62 
       
    63 #ifdef	__CPU_HAS_CP15_THREAD_ID_REG
       
    64 	asm("mov	r0, #0 ");
       
    65 	SET_RWNO_TID(,r0);			// initialise SubScheduler() pointer to 0
       
    66 	SET_RWRO_TID(,r0);
       
    67 	SET_RWRW_TID(,r0);
       
    68 #endif
       
    69 
       
    70 	asm("bl HwInit0 ");
       
    71 
       
    72 	asm("ldr r4, __CtorList ");
       
    73 	
       
    74 	asm("1: ");
       
    75 	asm("ldr r0, [r4, #4]! ");
       
    76 	asm("adr lr, 1b ");
       
    77 	asm("cmp r0, #0 ");
       
    78 	asm("mrs r1, cpsr ");
       
    79 	ASM_DEBUG2(GlobalCtor,r0,r1);
       
    80 	__JUMP(ne,r0);
       
    81 
       
    82 	asm("b KernelMain ");
       
    83 
       
    84 	asm("__RomHeaderAddress: ");
       
    85 	asm(".word RomHeaderAddress ");
       
    86 	asm("__SuperPage: ");
       
    87 	asm(".word SuperPageAddress ");
       
    88 	asm("__CtorList: ");
       
    89 	asm(".word __CTOR_LIST__ ");
       
    90 	}
       
    91 #elif defined(__ARMCC__)
       
    92 void __DLL_Export_Table__(void);
       
    93 void __cpp_initialize__aeabi_();
       
    94   
       
    95 // The compiler generates calls to this when it reckons a top-level construction
       
    96 // needs destruction. But the kernel never will need this so, define it as a nop
       
    97 void __record_needed_destruction (void * d){}
       
    98 // 2.1 calls __aeabi_atexit passing __dso_handle. This can be a dummy (i.e. just a label)
       
    99 
       
   100 __asm void __dso_handle(void) {}
       
   101 void __aeabi_atexit(void *object, void (*dtor)(void *), void *handle){}
       
   102 
       
   103 void _E32Startup_Body(TLinAddr aRomHeader, TLinAddr aSuperPage);
       
   104 
       
   105 __NAKED__ void _E32Startup(TLinAddr aRomHeader, TLinAddr aSuperPage)
       
   106 	{
       
   107 	EKA2_ENTRY_POINT_VERSION_IDENTIFIER;	// DUMMY INSTRUCTION TO INDICATE EKA2 ENTRY POINT
       
   108 	asm("b		1f ");
       
   109 	asm(".word	0 ");			// padding
       
   110 
       
   111 	asm(".word	0 ");			// loader will replace with code seg unique ID
       
   112 								// for RAM-loaded code segment
       
   113 								// MUST BE AT OFFSET 12 FROM ENTRY POINT
       
   114 	asm("1:		");
       
   115 #ifdef	__CPU_HAS_CP15_THREAD_ID_REG
       
   116 	asm("mov	r12, #0 ");
       
   117 	SET_RWNO_TID(,r12);			// initialise SubScheduler() pointer to 0
       
   118 	SET_RWRO_TID(,r12);
       
   119 	SET_RWRW_TID(,r12);
       
   120 #endif
       
   121 	asm("mov	r12, #0 ");
       
   122 	SET_RWNO_TID(,r12);			// initialise SubScheduler() pointer to 0
       
   123 	asm("b		_E32Startup_Body ");
       
   124 
       
   125 	}
       
   126 
       
   127 GLDEF_C void _E32Startup_Body(TLinAddr aRomHeader, TLinAddr aSuperPage)
       
   128 	{
       
   129 	RomHeaderAddress = aRomHeader;
       
   130 	SuperPageAddress = aSuperPage;
       
   131 	HwInit0();
       
   132 
       
   133 	// RVCT specific initialization
       
   134 
       
   135 	// Make sure we get an export table
       
   136 	__DLL_Export_Table__();
       
   137 
       
   138 	// Initialise static data
       
   139 	__cpp_initialize__aeabi_();
       
   140 
       
   141 	KernelMain();
       
   142 	}
       
   143 #else
       
   144 #error Not supported
       
   145 #endif
       
   146 
       
   147 }
       
   148