MIPS HardwareにおけるKSEG0, 1, 2のアドレス変換とTLB

KSEG0, 1におけるマッピングはハードとkernelがどう連携しているのか調査した。結論としては、ハード側でTLBにVirtualAddressを渡す前にチェック

例1)
  • pc(virtual address)の上位2 or 3bitが
    • 100 : KSEG0 (2.0G - 2.5G)
    • 101 : KSEG1 (2.5G - 3.0G)
    • 11 : KSEG2 (3.0G - 4.0G)

その結果をみてTLBを使うかどうか判断して、PFN (Physical Frame Number) or PPN(Physical Page Number)を算出

wire tlb_use_at_idle = fetch_state == FETCH_IDLE && (if_pc[31] == 1'b0 || if_pc[31:30] == 2'b11);

wire [19:0] pfn_at_idle = 
    (~(tlb_use_at_idle))?   { 3'b0, if_pc[28:12] } :
    (micro_check_matched)?  micro_check_result[39:20] :
                            tlb_ram_fetch_result[39:20];

aoR3000/pipeline_if.v at b459a2326825652e8d2f8e542a7dddf94e4c25ea · alfikpl/aoR3000 · GitHub

例2)

直接比較

    // If instuction memory is unmapped, just pass
    // it through after removing the offsets
    if( (inst_virtual_address >= `KSEG0_START) &&
      (inst_virtual_address <= `KSEG0_END)) begin
      inst_physical_address = (inst_virtual_address - `KSEG0_START);
    end
    else if( (inst_virtual_address >= `KSEG1_START) &&
         (inst_virtual_address <= `KSEG1_END)) begin
      inst_physical_address = (inst_virtual_address - `KSEG1_START);
    end
    else begin

https://alexander.soto.io/mips-processor