github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/arm/mmu.s (about)

     1  // ARM processor support
     2  // https://github.com/usbarmory/tamago
     3  //
     4  // Copyright (c) WithSecure Corporation
     5  // https://foundry.withsecure.com
     6  //
     7  // Use of this source code is governed by the license
     8  // that can be found in the LICENSE file.
     9  
    10  #include "textflag.h"
    11  
    12  // func flush_tlb()
    13  TEXT ·flush_tlb(SB),NOSPLIT,$0
    14  	MOVW	$0, R0
    15  
    16  	// Data Memory Barrier
    17  	MCR	15, 0, R0, C7, C10, 5
    18  
    19  	// Invalidate Instruction Cache
    20  	MCR	15, 0, R0, C7, C5, 0
    21  
    22  	// Data Synchronization Barrier
    23  	MCR	15, 0, R0, C7, C10, 4
    24  
    25  	// Invalidate unified TLB
    26  	MCR	15, 0, R0, C8, C7, 0
    27  
    28  	RET
    29  
    30  // func set_ttbr0(addr uint32)
    31  TEXT ·set_ttbr0(SB),NOSPLIT,$0-4
    32  	// Set TTBR0
    33  	MOVW	addr+0(FP), R0
    34  	MCR	15, 0, R0, C2, C0, 0
    35  
    36  	// Use TTBR0 for translation table walks
    37  	MOVW	$0, R0
    38  	MCR	15, 0, R0, C2, C0, 2
    39  
    40  	// Set Domain Access
    41  	MOVW	$1, R0
    42  	MCR	15, 0, R0, C3, C0, 0
    43  
    44  	// Enable MMU
    45  	MRC	15, 0, R0, C1, C0, 0
    46  	ORR	$1, R0
    47  	MCR	15, 0, R0, C1, C0, 0
    48  
    49  	CALL	·flush_tlb(SB)
    50  
    51  	RET