Commit 7ddbbeed authored by Jeffrey Lee's avatar Jeffrey Lee Committed by ROOL
Browse files

Define OS_Memory 0 page block format

Add to s.ChangeDyn a definition of the OS_Memory 0 page block format,
and update all relevant code to use those definitions instead of
hardcoded offsets.
parent 5bd42912
......@@ -162,10 +162,16 @@ ChangeDyn_Batcall * -3 ; special DA number to select Batman usa
; -2 was an internal value, now no longer used
; -> See hdr.OSMem for other area definitions
^ 0
MemPageBlock32_PageNum # 4
MemPageBlock32_LogAddr # 4
MemPageBlock32_PhysAddr # 4
MemPageBlock32_Size # 0
; Number of entries in page block on stack
NumPageBlockEntries * 63
PageBlockSize * NumPageBlockEntries * 12
PageBlockSize * NumPageBlockEntries * MemPageBlock32_Size
PageBlockChunk * NumPageBlockEntries * 4096
;
......@@ -5564,11 +5570,13 @@ DoTheGrow ROUT
FastCDA_ProfStart DoTheGrowInit, r0, r1, lr
ADR r1, PageBlock1 ; point at 1st page block on stack
ASSERT MemPageBlock32_Size = 12
ADD lr, r2, r2, LSL #1 ; lr = number of words in page block
ADD lr, r1, lr, LSL #2 ; lr -> off end of page block
MOV r0, #-1
10
STR r0, [lr, #-12]! ; store -1, going backwards
ASSERT MemPageBlock32_PageNum = 0
STR r0, [lr, #-MemPageBlock32_Size]!; store -1, going backwards
STR r0, [lr, #PageBlockSize] ; and put -1 in 2nd page block as well
TEQ lr, r1 ; until the end
BNE %BT10
......@@ -5582,7 +5590,7 @@ DoTheGrow ROUT
; now check to see if particular pages are required
LDR lr, [r1] ; load page number in 1st entry
LDR lr, [r1, #MemPageBlock32_PageNum] ; load page number in 1st entry
CMP lr, #-1 ; is it -1?
BNE DoTheGrowPagesSpecified ; if not, then jump to special code
......@@ -5604,7 +5612,8 @@ DoTheGrowPageUnavailable ROUT
ADR r2, PageBlock1
38
LDR r4, [r1, #-12]! ; r4 = physical page number
ASSERT MemPageBlock32_PageNum=0
LDR r4, [r1, #-MemPageBlock32_Size]! ; r4 = physical page number
ADD r4, r0, r4, LSL #CAM_EntrySizeLog2 ; point at cam entry
ASSERT CAM_PageFlags=4
LDMIA r4, {r8, lr}
......@@ -5654,13 +5663,14 @@ DoTheGrowPagesSpecified ROUT
LDR r0, =ZeroPage
LDR r0, [r0, #CamEntriesPointer]
05
LDR r3, [r1], #12 ; r4 = physical page number
ASSERT MemPageBlock32_PageNum=0
LDR r3, [r1], #MemPageBlock32_Size ; r4 = physical page number
ADD r4, r0, r3, LSL #CAM_EntrySizeLog2 ; point at cam entry
ASSERT CAM_LogAddr=0
ASSERT CAM_PageFlags=4
LDMIA r4, {r8, lr} ; r8 = log. addr, lr = PPL
STR r8, [r1, #4-12] ; store log. addr in page block
STR r8, [r1, #PageBlockSize+4-12] ; and in 2nd page block
STR r8, [r1, #MemPageBlock32_LogAddr-MemPageBlock32_Size] ; store log. addr in page block
STR r8, [r1, #PageBlockSize+MemPageBlock32_LogAddr-MemPageBlock32_Size] ; and in 2nd page block
TST lr, r6 ; if page in use by someone else, or by us, then return error
BNE DoTheGrowPageUnavailable
......@@ -5681,7 +5691,7 @@ DoTheGrowPagesSpecified ROUT
CMP r8, #1:SHL:20 ; 4GB limit
BHS DoTheGrowPageUnavailable
MOV r8, r8, LSL #12
STR r8, [r1, #8-12] ; store physical address in page block
STR r8, [r1, #MemPageBlock32_PhysAddr-MemPageBlock32_Size] ; store physical address in page block
SUBS r2, r2, #1
BNE %BT05
......@@ -5741,8 +5751,9 @@ DoTheGrowPagesSpecified ROUT
FastCDA_ProfStart FindSpare, r6, r1, lr
20
LDR r6, [r8], #12 ; r6 = page number required
LDR r10, [r8, #8-12] ; r10 = phys addr
ASSERT MemPageBlock32_PageNum=0
LDR r6, [r8], #MemPageBlock32_Size ; r6 = page number required
LDR r10, [r8, #MemPageBlock32_PhysAddr-MemPageBlock32_Size] ; r10 = phys addr
; r0 = End of area being removed from src (DANode_PMP+DANode_PMPSize*4)
; r1 = Spare
......@@ -5816,8 +5827,9 @@ DoTheGrowPagesSpecified ROUT
; DREG r6, "Using page number "
68
STR r6, [r8, #PageBlockSize-12] ; store page number in 2nd block
STR r10, [r8, #PageBlockSize+8-12] ; and store phys addr
ASSERT MemPageBlock32_PageNum=0
STR r6, [r8, #PageBlockSize-MemPageBlock32_Size] ; store page number in 2nd block
STR r10, [r8, #PageBlockSize+MemPageBlock32_PhysAddr-MemPageBlock32_Size] ; and store phys addr
SUBS r9, r9, #1 ; one less entry to do
BNE %BT20
......@@ -5847,7 +5859,7 @@ DoTheGrowPagesSpecified ROUT
STR r14, SavedPSR ; save old PSR (note: stack must be flat when we do this!)
; Grab the flags for the page we're replacing; in order to preserve the contents of the page we may map it to its destination early, causing the flags in the CAM map to be "wrong" when we read them back out later on
LDR r11, [r8, #0] ; need to get PPL for page being replaced
LDR r11, [r8, #MemPageBlock32_PageNum] ; need to get PPL for page being replaced
ADD lr, r0, #CAM_PageFlags ; point at PPLs, not addresses
LDR r11, [lr, r11, LSL #CAM_EntrySizeLog2]
MOV lr, #1
......@@ -5864,7 +5876,7 @@ DoTheGrowPagesSpecified ROUT
WritePSRc I_bit+SVC_mode, r6 ; disable IRQs round here (we don't want interrupt code to update
; the old mapping behind us while we're trying to copy it)
LDR lr, [r8, #PageBlockSize+0] ; lr = page number of replacement page
LDR lr, [r8, #PageBlockSize+MemPageBlock32_PageNum] ; lr = page number of replacement page
; The replacement page will be a member of the free pool PMP - remove it
; from the PMP now, before any CAM updates make it hard to get access
......@@ -5877,7 +5889,7 @@ DoTheGrowPagesSpecified ROUT
STR r3, [r2, r6, LSL #2]
; If the required page is a member of a PMP, update its PMP to point to
; the replacement page (and update the CAM for the replacement)
LDR r6, [r8, #0]
LDR r6, [r8, #MemPageBlock32_PageNum]
TEQ r6, lr
BEQ %FT72 ; Required == replacement, leave unassociated
ADD r6, r0, r6, LSL #CAM_EntrySizeLog2
......@@ -5892,7 +5904,7 @@ DoTheGrowPagesSpecified ROUT
STR lr, [r4, r6, LSL #2] ; And update PMP of required page to point to replacement
72
LDR r6, [r8, #0] ; r6 = page number required
LDR r6, [r8, #MemPageBlock32_PageNum] ; r6 = page number required
TEQ r6, lr ; if the same
Pull "r0-r4,r7-r12", EQ ; then restore registers
BEQ %FT86 ; and skip copy and first page move
......@@ -5903,7 +5915,7 @@ DoTheGrowPagesSpecified ROUT
; The old scheme, always copying from other mapping, had interrupt cache coherency hole, at least for
; ARM with writeback cache (bug in 3.7, fixed in Ursula, then lost)
LDR r6, [r8, #4] ;logical address of src page
LDR r6, [r8, #MemPageBlock32_LogAddr] ;logical address of src page
; If the required page is in the free pool, we don't need to preserve its contents
; TODO - have 'volatile' page flag which can be used to indicate that pages can just be taken? (so will work with any PMP)
......@@ -5924,7 +5936,7 @@ DoTheGrowPagesSpecified ROUT
LDR r11, [sp, #11*4+:INDEX:DestFlags]
TEQ r3, r2
BEQ %FT75 ; Dest is Nowhere - must use temp mapping
LDR r2, [r8, #0]
LDR r2, [r8, #MemPageBlock32_PageNum]
FastCDA_ProfStart MoveNeeded, lr, r4, r7
BL Call_CAM_Mapping ; move needed page to destination
FastCDA_ProfEnd MoveNeeded, lr, r4, r7
......@@ -5949,7 +5961,7 @@ ReplacePage_DestUnmapped
Push "r1"
FastCDA_ProfStart AccessPhysical, r2, r1, lr
LDR r0, =OSAP_None+DynAreaFlags_NotCacheable
LDR r1, [r8, #PageBlockSize+8] ; r1 = physical address of dest for copy
LDR r1, [r8, #PageBlockSize+MemPageBlock32_PhysAddr] ; r1 = physical address of dest for copy
MOV r2, #0
ADD r3, sp, #4
BL AccessPhysicalAddress
......@@ -5969,7 +5981,7 @@ ReplacePage_BothUnmapped
Push "r0,r1"
FastCDA_ProfStart AccessPhysical, r0, r1, lr
LDR r0, =OSAP_None+DynAreaFlags_NotCacheable
LDR r1, [r8, #8] ; r1 = physical address of src for copy
LDR r1, [r8, #MemPageBlock32_PhysAddr] ; r1 = physical address of src for copy
MOV r2, #0
ADD r3, sp, #8
BL AccessPhysicalAddress
......@@ -5992,7 +6004,7 @@ ReplacePage_BothUnmapped
; Now map in dest
LDR r0, =OSAP_None+DynAreaFlags_NotCacheable
LDR r1, [r8, #PageBlockSize+8] ; r1 = physical address of dest for copy
LDR r1, [r8, #PageBlockSize+MemPageBlock32_PhysAddr] ; r1 = physical address of dest for copy
MOV r2, #0
MOV r3, #0 ; no oldp needed
BL AccessPhysicalAddress
......@@ -6018,7 +6030,7 @@ ReplacePage_SrcUnmapped
Push "r0,r1"
FastCDA_ProfStart AccessPhysical, r0, r1, lr
LDR r0, =OSAP_None+DynAreaFlags_NotCacheable
LDR r1, [r8, #8] ; r1 = physical address of src for copy
LDR r1, [r8, #MemPageBlock32_PhysAddr] ; r1 = physical address of src for copy
MOV r2, #0
ADD r3, sp, #8
BL AccessPhysicalAddress
......@@ -6054,8 +6066,8 @@ ReplacePage_Done
; now check if page we're replacing is in L2PT, and if so then adjust L1PT entries (4 of these)
LDR r0, [r8, #4] ; look at logical address of page being replaced
LDR r1, [r8, #PageBlockSize+8] ; load new physical address for page
LDR r0, [r8, #MemPageBlock32_LogAddr] ; look at logical address of page being replaced
LDR r1, [r8, #PageBlockSize+MemPageBlock32_PhysAddr] ; load new physical address for page
BL UpdateL1PTForPageReplacement
84
......@@ -6093,7 +6105,7 @@ ReplacePage_Done
FastCDA_ProfStart ChangingEntry, r6, lr, r4
]
; Use BangCam to remove the cacheability on the needed page
LDR r2, [r8, #0] ; Get page number of needed page
LDR r2, [r8, #MemPageBlock32_PageNum] ; Get page number of needed page
ORR r11, r11, #1<<TempUncacheableShift ; Make temp uncache
BL Call_CAM_Mapping ; This will flush the TLB for us, but won't flush the cache
; So now we flush the cache manually
......@@ -6110,7 +6122,7 @@ ReplacePage_Done
BL Call_CAM_Mapping ; move replacement page in
FastCDA_ProfEnd MoveReplacement, r6, lr, r5
86
LDR r2, [r8, #0]
LDR r2, [r8, #MemPageBlock32_PageNum]
MOV r3, r1
LDR r11, DestFlags
LDRB lr, NeedToMoveFlag
......@@ -6138,7 +6150,7 @@ ReplacePage_Done
ADD r1, r1, r5 ; advance dest ptr
ADD r4, r4, r5 ; increment amount done
ADD r8, r8, #12 ; advance page block ptr
ADD r8, r8, #MemPageBlock32_Size ; advance page block ptr
CMP r4, r7 ; have we done all?
BNE %BT70 ; [no, so loop]
......@@ -6424,7 +6436,7 @@ CallPreGrow ROUT
LDR lr,[r4,r2,LSL #CAM_EntrySizeLog2]
TST lr,#PageFlags_Unavailable :OR: PageFlags_Required
TSTEQ lr,#PageFlags_Reserved
STREQ r2,[r1],#12
STREQ r2,[r1],#MemPageBlock32_Size
SUBEQS r3,r3,#4096
BEQ %FT80
SUBS r12,r12,#1
......
......@@ -168,6 +168,10 @@ MemoryConvertNoFIQCheck ROUT
SUBS r2, r2, #1
BCC %FT70
ASSERT MemPageBlock32_PageNum=0
ASSERT MemPageBlock32_LogAddr=4
ASSERT MemPageBlock32_PhysAddr=8
ASSERT MemPageBlock32_Size=12
LDMIA r1!, {r3-r4,r8} ; Get next three word entry (PN,LA,PA) and move on pointer.
! 0, "LongDescTODO 4GB"
MOV r9, #0 ; Top half of PA is zero
......@@ -188,8 +192,8 @@ MemoryConvertNoFIQCheck ROUT
CMPCC r9, #1
BCS %FT80
TST r0, #logical,wanted
STRNE r4, [r1, #-8] ; Store back LA if wanted.
STR r8, [r1, #-4] ; Store back PA.
STRNE r4, [r1, #MemPageBlock32_LogAddr-MemPageBlock32_Size] ; Store back LA if wanted.
STR r8, [r1, #MemPageBlock32_PhysAddr-MemPageBlock32_Size] ; Store back PA.
20
TST r0, #alter_cacheable ; If altering cacheability
EORNE lr, r0, #ppn,given ; and PN not given
......@@ -201,7 +205,7 @@ MemoryConvertNoFIQCheck ROUT
BLCC physical_to_ppn ; Get PN from PA.
BCS %FT80
TST r0, #ppn,wanted
STRNE r3, [r1, #-12] ; Store back PN if wanted.
STRNE r3, [r1, #MemPageBlock32_PageNum-MemPageBlock32_Size] ; Store back PN if wanted.
30
TST r0, #logical,wanted ; If LA wanted
EORNE lr, r0, #physical,wanted
......@@ -212,7 +216,7 @@ MemoryConvertNoFIQCheck ROUT
BLEQ physical_to_ppn ; get it from PA (LA wanted (not given) & PN not given => PA given).
BLCC ppn_to_logical ; Get LA from PN.
BCS %FT80
STR r4, [r1, #-8] ; Store back LA.
STR r4, [r1, #MemPageBlock32_LogAddr-MemPageBlock32_Size] ; Store back LA.
40
TST r0, #alter_cacheable
BEQ %BT10
......
......@@ -303,7 +303,7 @@ ShuffleDoublyMappedRegionForGrow ROUT
EXIT
; R2 = grow amount, bytes
; R3 = page list to add page numbers to, or null if not needed
; R3 = 32bit page list to add page numbers to, or null if not needed
; R11 = src DANode (free pool)
; R12 = dest DANode
DoTheGrowCommon ROUT
......@@ -355,7 +355,8 @@ DoTheGrowCommon ROUT
ADD r1, r1, #PageSize
TEQ r3, #0
ADD r4, r4, #PageSize
STRNE r2, [r3], #12 ; store page number and move on
ASSERT MemPageBlock32_PageNum = 0
STRNE r2, [r3], #MemPageBlock32_Size ; store page number and move on
CMP r4, r10 ; have we done all of it?
BNE %BT30 ; [no, so loop]
[ FastCDA_Bulk
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment