设置TLB属性后,如何防止对其进行修改?

时间:2019-04-10 15:56:53

标签: armv7 tlb zynq

我正在为Zynq ZC702编写两个裸机应用程序,一个在每个CPU上运行。我将它们分别称为app0和app1,分别在CPU0和CPU1上运行。每个应用程序应具有另一个不能读取的DDR内存专用区域。因此,例如,如果app1的专用区域为0x18000000至0x20000000,则在app0的初始化期间,我将在CPU0的TLB中设置128个对应的条目(每MB 1个),以将该区域标记为不可访问(全零的属性,如果尝试进行任何访问,则导致数据中止) )。

这有效,但是仍然可以修改内存中的TLB以删除此保护。我正在尝试提出一种保护TLB的方法,例如将其属性设置为只读,可能使用L2表来获取4KB的粒度,尽管L2表也必须将自身设置为只读。 。 L1表为16KB,L2表为1KB,因此总共5个L2条目可以覆盖它们。 但是我不确定如何将表分配到应用程序内存之外的位置,以便使第5个L2条目变为只读的额外3KB内容不包含任何重要内容。

我从Xilinx forums的线程中获得了一些信息,但是我不确定自己是否走在正确的轨道上。我觉得有一种更合适的方法可以完成此任务。我将Xilinx SDK 2017.2与每个内核的默认BSP一起使用。

我在BSP的translation_table.S中定义的.mmu_tbl节中添加了一个L2表。这是我在启用MMU之前不久添加到默认boot.S中的一些代码。我逐步执行以确保L2条目已按预期进行更新。

protect_tables:
    /* Map L2 table to L1 entry */
    ldr r0, =TblBase
    ldr r1, =L2Base
    lsr r3, r0, #20         /* get section number where the MMU Table is held */
    lsl r3, r3, #2          /* multiply by 4 to get offset into MMU Table */
    add r3, r0, r3          /* address of entry in MMU table that covers itself */
    ldr r6, =0x1e1          /* Domain=b1111 */
    add r2, r1, r6          /* combine L2Base address with domain info to create the entry */
    str r2, [r3]            /* Write entry in MMU table */
/* Set up L2 Table to protect MMU table and itself */
    and r3, r0, #0x000ff000 /* 4KB subsection where MMU table starts */
    lsr r3, r3, #10         /* offset into L2 Table */
    add r3, r1, r3          /* address of entry in L2 table that covers first 4KB of MMU table */
    ldr r6, =0x366          /* S=b0 TEX=b101 AP=b110, C=b0, B=b1 */
    add r2, r0, r6          /* combine address and attributes to create an entry */
    ldr r4, =5              /* loop control. Store 5 consecutive entries */
mmu_protection_loop:
    str r2, [r3]            /* write the entry to L2 table */
    add r3, r3, #4          /* next entry in the table */
    add r2, r2, #0x1000     /* next 4KB subsection */
    subs r4, r4, #1
    bgt mmu_protection_loop

我在这5个小节中设置的属性应该使它们成为只读的。但是,如果以后尝试在任一表中写入条目,它仍然允许写入。

0 个答案:

没有答案