os/kernelhwsrv/kernel/eka/memmodel/epoc/moving/arm/xkernel.cia
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 1994-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32\memmodel\epoc\moving\arm\xkernel.cia
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#include <e32cia.h>
sl@0
    19
#include <arm_mem.h>
sl@0
    20
sl@0
    21
__NAKED__ void DArmPlatChunk::MoveHomePdes(TLinAddr /*aOldAddr*/, TLinAddr /*aNewAddr*/)
sl@0
    22
	{
sl@0
    23
	asm("mov r2, r2, lsr #20 ");			// r2=pde index for new addr
sl@0
    24
	asm("subs r2, r2, r1, lsr #20 ");		// subtract pde index for old addr
sl@0
    25
	__JUMP(eq,lr);							// if zero, nothing to do
sl@0
    26
	asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iNumPdes));
sl@0
    27
	asm("cmp r1, #0 ");
sl@0
    28
	__JUMP(eq,lr);							// if chunk empty, nothing to do
sl@0
    29
	asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomePdes));
sl@0
    30
	asm("add r1, r1, r2, asl #2 ");			// move home pde address
sl@0
    31
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomePdes));
sl@0
    32
	__JUMP(,lr);
sl@0
    33
	}
sl@0
    34
sl@0
    35
__NAKED__ void DArmPlatChunk::MoveCurrentPdes(TLinAddr /*aOldAddr*/, TLinAddr /*aNewAddr*/)
sl@0
    36
	{
sl@0
    37
	asm("mov r2, r2, lsr #20 ");			// r2=pde index for new addr
sl@0
    38
	asm("subs r2, r2, r1, lsr #20 ");		// subtract pde index for old addr
sl@0
    39
	__JUMP(eq,lr);							// if zero, nothing to do
sl@0
    40
	asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iNumPdes));
sl@0
    41
	asm("cmp r1, #0 ");
sl@0
    42
	__JUMP(eq,lr);							// if chunk empty, nothing to do
sl@0
    43
	asm("ldr r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdes));
sl@0
    44
	asm("add r1, r1, r2, asl #2 ");			// move current pde address
sl@0
    45
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdes));
sl@0
    46
	__JUMP(,lr);
sl@0
    47
	}
sl@0
    48
sl@0
    49
__NAKED__ void DArmPlatChunk::AddPde(TInt /*aOffset*/)
sl@0
    50
	{
sl@0
    51
	asm("mov r1, r1, lsr #20 ");			// r1=pde number
sl@0
    52
	asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iMaxSize));
sl@0
    53
	asm("cmp r2, #0x02000000 ");
sl@0
    54
	asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdeBitMap));
sl@0
    55
	asm("bhi add_pde_large ");
sl@0
    56
	asm("mov ip, #1 ");
sl@0
    57
	asm("orr r3, r3, ip, lsl r1 ");			// set bit in bitmap
sl@0
    58
	asm("str r3, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdeBitMap));
sl@0
    59
	asm("b scan_small_bitmap ");
sl@0
    60
sl@0
    61
	asm("add_pde_large: ");
sl@0
    62
	asm("stmfd sp!, {r4,lr} ");
sl@0
    63
	asm("mov lr, r1, lsr #5 ");				// lr=word number in bitmap
sl@0
    64
	asm("and r1, r1, #31 ");				// r1=bit number in word
sl@0
    65
	asm("ldr r4, [r3, lr, lsl #2] ");
sl@0
    66
	asm("mov ip, #1 ");
sl@0
    67
	asm("orr r4, r4, ip, lsl r1 ");
sl@0
    68
	asm("str r4, [r3, lr, lsl #2] ");		// set bit in bitmap
sl@0
    69
	asm("b scan_large_bitmap ");
sl@0
    70
	}
sl@0
    71
sl@0
    72
__NAKED__ void DArmPlatChunk::RemovePde(TInt /*anOffset*/)
sl@0
    73
	{
sl@0
    74
	asm("mov r1, r1, lsr #20 ");			// r1=pde number
sl@0
    75
	asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iMaxSize));
sl@0
    76
	asm("cmp r2, #0x02000000 ");
sl@0
    77
	asm("ldr r3, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdeBitMap));
sl@0
    78
	asm("bhi rem_pde_large ");
sl@0
    79
	asm("mov ip, #1 ");
sl@0
    80
	asm("bics r3, r3, ip, lsl r1 ");		// clear bit in bitmap
sl@0
    81
	asm("str r3, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdeBitMap));
sl@0
    82
	asm("beq empty_chunk ");				// if chunk empty, skip rest
sl@0
    83
sl@0
    84
	asm("scan_small_bitmap: ");				// r3 contains nonzero bitmap
sl@0
    85
#ifdef __CPU_ARM_HAS_CLZ
sl@0
    86
	asm("sub r2, r3, #1 ");					// ip will hold index of first pde
sl@0
    87
	asm("eor r2, r2, r3 ");
sl@0
    88
	CLZ(12,2);
sl@0
    89
	asm("rsb r12, r12, #31 ");
sl@0
    90
	asm("mov r3, r3, lsr r12 ");			// shift bitmap so bit 0 set
sl@0
    91
	CLZ(1, 3);
sl@0
    92
	asm("rsb r1, r1, #32 ");				// r1 will be 1+most significant 1 in r3	
sl@0
    93
#else
sl@0
    94
	asm("mov ip, #0 ");						// ip will hold index of first pde
sl@0
    95
	asm("movs r2, r3, lsl #16 ");			// test if bottom 16 bits zero
sl@0
    96
	asm("moveq r3, r3, lsr #16 ");			// if bottom 16 zero, shift right by 16
sl@0
    97
	asm("addeq ip, ip, #16 ");				// and add 16 to lsb index
sl@0
    98
	asm("tst r3, #0xff ");
sl@0
    99
	asm("moveq r3, r3, lsr #8 ");
sl@0
   100
	asm("addeq ip, ip, #8 ");
sl@0
   101
	asm("tst r3, #0x0f ");
sl@0
   102
	asm("moveq r3, r3, lsr #4 ");
sl@0
   103
	asm("addeq ip, ip, #4 ");
sl@0
   104
	asm("tst r3, #0x03 ");
sl@0
   105
	asm("moveq r3, r3, lsr #2 ");
sl@0
   106
	asm("addeq ip, ip, #2 ");
sl@0
   107
	asm("tst r3, #0x01 ");
sl@0
   108
	asm("moveq r3, r3, lsr #1 ");
sl@0
   109
	asm("addeq ip, ip, #1 ");				// ip=number of right shifts applied, r3 bit 0 set
sl@0
   110
	asm("mov r1, #32 ");					// r1 will be 1+most significant 1 in r3
sl@0
   111
	asm("cmp r3, #0x00010000 ");
sl@0
   112
	asm("movcc r3, r3, lsl #16 ");
sl@0
   113
	asm("subcc r1, r1, #16 ");
sl@0
   114
	asm("cmp r3, #0x01000000 ");
sl@0
   115
	asm("movcc r3, r3, lsl #8 ");
sl@0
   116
	asm("subcc r1, r1, #8 ");
sl@0
   117
	asm("cmp r3, #0x10000000 ");
sl@0
   118
	asm("movcc r3, r3, lsl #4 ");
sl@0
   119
	asm("subcc r1, r1, #4 ");
sl@0
   120
	asm("cmp r3, #0x40000000 ");
sl@0
   121
	asm("movcc r3, r3, lsl #2 ");
sl@0
   122
	asm("subcc r1, r1, #2 ");
sl@0
   123
	asm("cmp r3, #0x80000000 ");
sl@0
   124
	asm("movcc r3, r3, lsl #1 ");
sl@0
   125
	asm("subcc r1, r1, #1 ");
sl@0
   126
#endif
sl@0
   127
sl@0
   128
	asm("scan_bitmap_end: ");
sl@0
   129
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iNumPdes));	// r1 gives number of PDEs in range
sl@0
   130
	asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iBase));
sl@0
   131
	asm("add r2, ip, r2, lsr #20 ");		// r2=pde index of first current pde
sl@0
   132
	asm("mov r2, r2, lsl #2 ");
sl@0
   133
	asm("add r2, r2, #%a0" : : "i" ((TInt)KPageDirectoryBase));			// r2->first current pde
sl@0
   134
	asm("str r2, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdes));
sl@0
   135
	asm("ldr r2, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomeBase));
sl@0
   136
	asm("add r2, ip, r2, lsr #20 ");		// r2=pde index of first home pde
sl@0
   137
	asm("mov r2, r2, lsl #2 ");
sl@0
   138
	asm("add r2, r2, #%a0" : : "i" ((TInt)KPageDirectoryBase));			// r2->first home pde
sl@0
   139
	asm("str r2, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomePdes));
sl@0
   140
	__JUMP(,lr);
sl@0
   141
sl@0
   142
	asm("empty_chunk: ");
sl@0
   143
	asm("mov r1, #0 ");
sl@0
   144
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iNumPdes));
sl@0
   145
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iPdes));
sl@0
   146
	asm("str r1, [r0, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomePdes));
sl@0
   147
	__JUMP(,lr);
sl@0
   148
sl@0
   149
	asm("rem_pde_large: ");
sl@0
   150
	asm("stmfd sp!, {r4,lr} ");
sl@0
   151
	asm("mov lr, r1, lsr #5 ");				// lr=word number in bitmap
sl@0
   152
	asm("and r1, r1, #31 ");				// r1=bit number in word
sl@0
   153
	asm("ldr r4, [r3, lr, lsl #2] ");
sl@0
   154
	asm("mov ip, #1 ");
sl@0
   155
	asm("bic r4, r4, ip, lsl r1 ");
sl@0
   156
	asm("str r4, [r3, lr, lsl #2] ");		// set bit in bitmap
sl@0
   157
sl@0
   158
	asm("scan_large_bitmap: ");
sl@0
   159
	// r0=this, r2=max size, r3->pde bit map
sl@0
   160
	asm("add r2, r2, #0x1f00000 ");
sl@0
   161
	asm("mov r2, r2, lsr #25 ");			// r2=number of words in bitmap
sl@0
   162
	asm("add r2, r3, r2, lsl #2 ");			// r2=bitmap end address
sl@0
   163
	asm("mov r4, r3 ");						// save bitmap start address
sl@0
   164
sl@0
   165
	asm("scan_large_1: ");
sl@0
   166
	asm("ldr ip, [r3], #4 ");
sl@0
   167
	asm("cmp ip, #0 ");
sl@0
   168
	asm("bne scan_large_2 ");				// found non-empty word
sl@0
   169
	asm("cmp r3, r2 ");
sl@0
   170
	asm("bne scan_large_1 ");				// if not reached end, do next word
sl@0
   171
	asm("ldmfd sp!, {r4,lr} ");
sl@0
   172
	asm("b empty_chunk ");					// branch if no bits set
sl@0
   173
sl@0
   174
	asm("scan_large_2: ");
sl@0
   175
	asm("sub r1, r3, r4 ");
sl@0
   176
	asm("sub r1, r1, #4 ");
sl@0
   177
	asm("mov r1, r1, lsl #3 ");				// r1=bit number of lsb of this word
sl@0
   178
#ifdef __CPU_ARM_HAS_CLZ
sl@0
   179
	asm("sub lr, ip, #1 ");					// ip will hold index of first pde
sl@0
   180
	asm("eor ip, lr, ip ");
sl@0
   181
	CLZ(12, 12);
sl@0
   182
	asm("rsb ip, ip, #31 ");
sl@0
   183
	asm("add r1, r1, ip ");					// r1 now = first occupied pde offset
sl@0
   184
#else
sl@0
   185
	asm("movs lr, ip, lsl #16 ");
sl@0
   186
	asm("moveq ip, ip, lsr #16 ");
sl@0
   187
	asm("addeq r1, r1, #16 ");
sl@0
   188
	asm("tst ip, #0xff ");
sl@0
   189
	asm("moveq ip, ip, lsr #8 ");
sl@0
   190
	asm("addeq r1, r1, #8 ");
sl@0
   191
	asm("tst ip, #0x0f ");
sl@0
   192
	asm("moveq ip, ip, lsr #4 ");
sl@0
   193
	asm("addeq r1, r1, #4 ");
sl@0
   194
	asm("tst ip, #0x03 ");
sl@0
   195
	asm("moveq ip, ip, lsr #2 ");
sl@0
   196
	asm("addeq r1, r1, #2 ");
sl@0
   197
	asm("tst ip, #0x01 ");
sl@0
   198
	asm("moveq ip, ip, lsr #1 ");
sl@0
   199
	asm("addeq r1, r1, #1 ");				// r1 now = first occupied pde offset
sl@0
   200
#endif
sl@0
   201
	
sl@0
   202
	asm("scan_large_3: ");
sl@0
   203
	asm("ldr ip, [r2, #-4]! ");				// fetch words from end of bitmap
sl@0
   204
	asm("cmp ip, #0 ");
sl@0
   205
	asm("beq scan_large_3 ");				// we know there is at least one non-zero word
sl@0
   206
	asm("sub r2, r2, r4 ");
sl@0
   207
	asm("mov r2, r2, lsl #3 ");				// r2=bit number of lsb of this word
sl@0
   208
#ifdef __CPU_ARM_HAS_CLZ
sl@0
   209
	CLZ(12, 12);
sl@0
   210
	asm("rsb ip, ip, #31 ");
sl@0
   211
	asm("add r2, r2, ip ");					// r2 now = last occupied pde offset
sl@0
   212
#else
sl@0
   213
	asm("movs lr, ip, lsr #16 ");
sl@0
   214
	asm("movne ip, lr ");
sl@0
   215
	asm("addne r2, r2, #16 ");
sl@0
   216
	asm("movs lr, ip, lsr #8 ");
sl@0
   217
	asm("movne ip, lr ");
sl@0
   218
	asm("addne r2, r2, #8 ");
sl@0
   219
	asm("movs lr, ip, lsr #4 ");
sl@0
   220
	asm("movne ip, lr ");
sl@0
   221
	asm("addne r2, r2, #4 ");
sl@0
   222
	asm("movs lr, ip, lsr #2 ");
sl@0
   223
	asm("movne ip, lr ");
sl@0
   224
	asm("addne r2, r2, #2 ");
sl@0
   225
	asm("movs lr, ip, lsr #1 ");
sl@0
   226
	asm("movne ip, lr ");
sl@0
   227
	asm("addne r2, r2, #1 ");				// r2 now = last occupied pde offset
sl@0
   228
#endif
sl@0
   229
	asm("sub r3, r2, r1 ");					// r3=last-first
sl@0
   230
	asm("mov ip, r1 ");						// ip=first
sl@0
   231
	asm("add r1, r3, #1 ");					// r1 = number of pdes in range
sl@0
   232
	asm("ldmfd sp!, {r4,lr} ");
sl@0
   233
	asm("b scan_bitmap_end ");				// go back to set pde info
sl@0
   234
	}
sl@0
   235
sl@0
   236
__NAKED__ TBool Exc::IsMagic(TLinAddr /*anAddress*/)
sl@0
   237
//
sl@0
   238
// Return TRUE if anAddress is a 'magic' exception handling instruction
sl@0
   239
//
sl@0
   240
	{
sl@0
   241
	asm("adr r1, __magic_addresses ");		// r1 points to list of magic addresses
sl@0
   242
	asm("is_magic_1: ");
sl@0
   243
	asm("ldr r2, [r1], #4 ");				// r2=next magic address to check
sl@0
   244
	asm("cmp r2, r0 ");						// is r0=magic address?
sl@0
   245
	asm("cmpne r2, #0 ");					// if not, have we reached end of list?
sl@0
   246
	asm("bne is_magic_1 ");					// if neither, check next address
sl@0
   247
	asm("movs r0, r2 ");					// r0=0 if not magic, r0 unchanged if magic
sl@0
   248
	__JUMP(,lr);
sl@0
   249
sl@0
   250
	asm("__magic_addresses: ");
sl@0
   251
	asm(".word __magic_address_kusaferead ");
sl@0
   252
	asm(".word __magic_address_saferead ");
sl@0
   253
	asm(".word __magic_address_kusafewrite ");
sl@0
   254
	asm(".word __magic_address_safewrite ");
sl@0
   255
	asm(".word __magic_address_msg_lookup_1 ");			// in preprocess handler
sl@0
   256
	asm(".word __magic_address_readdesheader1 ");
sl@0
   257
	asm(".word __magic_address_readdesheader2 ");
sl@0
   258
	asm(".word __magic_address_readdesheader3 ");
sl@0
   259
#ifdef __MESSAGE_MACHINE_CODED_2__
sl@0
   260
	asm(".word __magic_address_msg_lookup_2 ");
sl@0
   261
#endif
sl@0
   262
#ifdef __CLIENT_REQUEST_MACHINE_CODED__
sl@0
   263
	asm(".word __magic_address_client_request_callback");
sl@0
   264
	asm(".word __magic_address_svr_accept_1 ");
sl@0
   265
	asm(".word __magic_address_svr_accept_2 ");
sl@0
   266
	asm(".word __magic_address_svr_accept_3 ");
sl@0
   267
	asm(".word __magic_address_svr_accept_4 ");
sl@0
   268
	asm(".word __magic_address_svr_accept_5 ");
sl@0
   269
	asm(".word __magic_address_svr_accept_6 ");
sl@0
   270
	asm(".word __magic_address_svr_accept_7 ");
sl@0
   271
	asm(".word __magic_address_svr_accept_8 ");
sl@0
   272
#endif
sl@0
   273
#ifdef __REQUEST_COMPLETE_MACHINE_CODED__
sl@0
   274
	asm(".word __magic_address_reqc ");
sl@0
   275
	asm(".word __magic_address_kern_request_complete ");
sl@0
   276
#endif
sl@0
   277
	// list terminator
sl@0
   278
	asm(".word 0 ");
sl@0
   279
	}
sl@0
   280
sl@0
   281
__NAKED__ TAny* MM::CurrentAddress(DThread* /*aThread*/, const TAny* /*aPtr*/, TInt /*aSize*/, TBool /*aWrite*/)
sl@0
   282
//
sl@0
   283
// Return the current base address corresponding to run address region
sl@0
   284
// aPtr to aPtr+aBase-1 in the context of aThread.
sl@0
   285
// aWrite indicates whether the address is intended for writing (aWrite=TRUE) or reading (aWrite=FALSE).
sl@0
   286
// Return NULL if the address range is not all accessible to aThread for access type specified by aWrite.
sl@0
   287
// aWrite=FALSE allows access to the ROM and RAM-loaded code chunks whereas aWrite=TRUE disallows these.
sl@0
   288
// NOTE THIS FUNCTION CONTAINS KNOWLEDGE OF FIXED LINEAR ADDRESSES (the RAM drive and HIVECS area).
sl@0
   289
//
sl@0
   290
// ALLERT! the ip register returns a pointer to the chunk which contains the addresses (null if none)
sl@0
   291
//
sl@0
   292
	{
sl@0
   293
	asm("CurrentAddress:");
sl@0
   294
	asm("ldr r0, [r0, #%a0]" : : "i" _FOFF(DThread, iOwningProcess));
sl@0
   295
	asm("stmfd sp!, {r4,r5,lr} ");
sl@0
   296
	asm("eor r4, r1, #0x40000000 ");		// r4<0x20000000u for RAM drive
sl@0
   297
	asm("cmp r4, #0x20000000 ");			// Check for RAM drive - ASSUMES RAM DRIVE IS AT 40000000-5FFFFFFF
sl@0
   298
	asm("ldr lr, [r0, #%a0]!" : : "i" _FOFF(DMemModelProcess, iNumChunks));		// step r0 on to iChunks[0]
sl@0
   299
	asm("bcc lookup_chunk_3 ");				// branch if RAM drive
sl@0
   300
	asm("subs lr, lr, #1 ");
sl@0
   301
	asm("bcc lookup_chunk_2 ");				// no chunks so do read check
sl@0
   302
	asm("lookup_chunk_1: ");
sl@0
   303
	asm("ldmib r0!, {r4,ip} ");				// r4=data section base, ip=chunk ptr
sl@0
   304
	asm("add r0, r0, #4 ");					// move to next entry
sl@0
   305
	asm("subs r4, r1, r4 ");				// r4=offset
sl@0
   306
	asm("ldrcs r5, [ip, #%a0]" : : "i" _FOFF(DChunk,iMaxSize));	// if offset>=0, r5=chunk max size
sl@0
   307
	asm("cmpcs r4, r5 ");					// and compare offset to max size
sl@0
   308
	asm("subcss lr, lr, #1 ");				// if offset>=max size, decrement counter
sl@0
   309
	asm("bcs lookup_chunk_1 ");				// loop if more chunks to check
sl@0
   310
	asm("cmp lr, #0 ");						// did we find chunk?
sl@0
   311
	asm("ldrge r0, [ip, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomeRegionOffset));
sl@0
   312
	asm("ldrge r5, [ip, #%a0]" : : "i" _FOFF(DMemModelChunk,iHomeRegionSize));
sl@0
   313
	asm("ldrge lr, [ip, #%a0]" : : "i" _FOFF(DChunk,iBase));
sl@0
   314
	asm("cmpge r4, r0 ");					// if chunk not found or offset<iHomeRegionOffset, do read check
sl@0
   315
	asm("blt lookup_chunk_2 ");
sl@0
   316
	asm("add r0, r0, r5 ");					// r0=home region offset+home region size
sl@0
   317
	asm("add r5, r4, r2 ");					// r5=offset after end of block
sl@0
   318
	asm("cmp r5, r0 ");						// check if offset after end<=iHomeRegionOffset+iHomeRegionSize
sl@0
   319
	asm("addle r0, lr, r4 ");				// if so, r0=current chunk base + offset
sl@0
   320
	asm("ldmlefd sp!, {r4,r5,pc} ");		// and we are done
sl@0
   321
sl@0
   322
	asm("lookup_chunk_2: ");				// come here if address not found in a chunk
sl@0
   323
	asm("mov ip, #0");						// ip = 0 to indicate chunk not found
sl@0
   324
	asm("ldr r4, __code_limit ");
sl@0
   325
	asm("mov r0, #0 ");
sl@0
   326
	asm("cmn r1, #0x00100000 ");			// address in hivecs area?
sl@0
   327
	asm("ldr r4, [r4] ");					// r4 = lowest legitimate code address
sl@0
   328
	asm("ldmcsfd sp!, {r4,r5,pc} ");		// if in hivecs, return NULL
sl@0
   329
	asm("cmp r3, #0 ");						// is this address intended for writing?
sl@0
   330
	asm("ldmnefd sp!, {r4,r5,pc} ");		// if it is, return NULL
sl@0
   331
	asm("cmp r1, r4 ");						// check if address is in RAM-loaded code or ROM
sl@0
   332
	asm("ldmccfd sp!, {r4,r5,pc} ");		// if not, return NULL
sl@0
   333
	asm("adds r4, r1, r2 ");				// r4 = end address of requested region
sl@0
   334
	asm("ldmcsfd sp!, {r4,r5,pc} ");		// if it wrapped, return NULL
sl@0
   335
	asm("cmn r4, #0x100000 ");				// if it didn't wrap, check if it reaches into hivecs area
sl@0
   336
	asm("movls r0, r1 ");					// if not, addr is OK for reading
sl@0
   337
	asm("ldmfd sp!, {r4,r5,pc} ");
sl@0
   338
sl@0
   339
	asm("lookup_chunk_3: ");				// come here if address in RAM drive
sl@0
   340
	asm("mov ip, #0");						// ip = 0 to indicate chunk not found
sl@0
   341
	asm("ldr r3, __f32 ");					// r3=&K::TheFileServerProcess
sl@0
   342
	asm("sub r4, r0, #%a0" : : "i" _FOFF(DMemModelProcess, iNumChunks));	// r4=aThread->iOwningProcess
sl@0
   343
	asm("mov r0, #0 ");
sl@0
   344
	asm("ldr r3, [r3] ");					// r3=K::TheFileServerProcess
sl@0
   345
	asm("add r5, r1, r2 ");					// r5=end address of requested region + 1
sl@0
   346
	asm("cmp r5, #0x60000000 ");			// is this past the end of the RAM drive? ASSUMES ADDRESS OF RAM DRIVE
sl@0
   347
	asm("cmpls r3, r4 ");					// if not, is aThread part of F32?
sl@0
   348
	asm("moveq r0, r1 ");					// if it is, allow the access and return the address unaltered
sl@0
   349
	asm("ldmfd sp!, {r4,r5,pc} ");			// else return NULL
sl@0
   350
sl@0
   351
	asm("__f32: ");
sl@0
   352
	asm(".word  " CSM_ZN1K20TheFileServerProcessE );
sl@0
   353
	asm("__code_limit: ");
sl@0
   354
	asm(".word %a0" : : "i" ((TInt)&::TheMmu.iUserCodeBase) );
sl@0
   355
	}
sl@0
   356