pgtt/table.py
def map( self, region:mmap.Region ) -> None:
        """
        Map a region of memory in this translation table.
        """
        log.debug()
        log.debug(f"mapping region {hex(region.virtaddr)}->{hex(region.addr)} in level {self.level} table {self.chunk}")
        log.debug(region)
        assert(region.virtaddr >= self.va_base)
        assert(region.virtaddr + region.length <= self.va_base + mmu.entries_per_table * self.chunk)

        """
        Calculate number of chunks required to map this region.
        A chunk is the area mapped by each individual entry in this table.
        start_idx is the first entry in this table mapping part of the region.
        """
        num_chunks = region.length // self.chunk
        start_idx = (region.virtaddr // self.chunk) % mmu.entries_per_table

        """
        Check whether the region is "floating".
        If so, dispatch to next-level table and we're finished.

                    +--------------------+
                 // |                    |
            Chunk - |####################| <-- Floating region
                 \\ |                    |
                    +--------------------+
        """
        if num_chunks == 0:
            log.debug(f"floating region, dispatching to next-level table at index {start_idx}")
            self.prepare_next(start_idx)
            self.entries[start_idx].map(region)
            return

        """
        Check for any "underflow".
        If so, dispatch the underflow to next-level table and proceed.

                    +--------------------+
                 // |####################|
            Chunk - |####################|
                 \\ |####################|
                    +--------------------+
                 // |####################| <-- Underflow
            Chunk - |                    |
                 \\ |                    |
                    +--------------------+
        """
        underflow = region.virtaddr % self.chunk
        if underflow:
            log.debug(f"{underflow=}, dispatching to next-level table at index {start_idx}")
            self.prepare_next(start_idx)
            self.entries[start_idx].map(region.copy(length=(self.chunk - underflow)))
            start_idx = start_idx + 1
            region.length -= self.chunk - underflow
            region.virtaddr += self.chunk - underflow
            region.addr += self.chunk - underflow
            log.debug(f"remaining: {region.length}")

        """
        Handle any remaining complete chunks.
        """

        blocks_allowed = self.level >= (1 if args.tg_str == "4K" else 2)
        num_contiguous_blocks = 0
        num_chunks = region.length // self.chunk
        for i in range(start_idx, start_idx + num_chunks):
            log.debug(f"mapping complete chunk at index {i} {hex(region.addr)}")
            r = region.copy(virtaddr=region.virtaddr, addr=region.addr, length=self.chunk)
            if not blocks_allowed:
                self.prepare_next(i)
                self.entries[i].map(r)
            else:
                self.entries[i] = r
            num_contiguous_blocks += 1
            region.addr += self.chunk
            region.virtaddr += self.chunk
            region.length -= self.chunk


        self.entries[start_idx].num_contig = num_contiguous_blocks
        start_idx += num_chunks;
        """
        Check for any "overflow".
        If so, dispatch the overflow to next-level table and proceed.

                    +--------------------+
                 // |                    |
            Chunk - |                    |
                 \\ |####################| <-- Overflow
                    +--------------------+
                 // |####################|
            Chunk - |####################|
                 \\ |####################|
                    +--------------------+
        """
        overflow = region.length
        if overflow:
            log.debug(f"{overflow=}, dispatching to next-level table at index {start_idx}")
            self.prepare_next(start_idx, region.virtaddr)
            self.entries[start_idx].map(region.copy(addr=region.addr, virtaddr=region.virtaddr, length=overflow))
            region.length -= overflow

        if region.length != 0:
            log.error("Length error: {region.length}")

        log.debug("..")

        Map a region of memory in this translation table.
        
Map a region of memory in this translation table.
Map a region of memory in this translation table .
def map( self, region:mmap.Region ) -> None:
        log.debug()
        log.debug(f"mapping region {hex(region.virtaddr)}->{hex(region.addr)} in level {self.level} table {self.chunk}")
        log.debug(region)
        assert(region.virtaddr >= self.va_base)
        assert(region.virtaddr + region.length <= self.va_base + mmu.entries_per_table * self.chunk)
        num_chunks = region.length // self.chunk
        start_idx = (region.virtaddr // self.chunk) % mmu.entries_per_table
        if num_chunks == 0:
            log.debug(f"floating region, dispatching to next-level table at index {start_idx}")
            self.prepare_next(start_idx)
            self.entries[start_idx].map(region)
            return
        underflow = region.virtaddr % self.chunk
        if underflow:
            log.debug(f"{underflow=}, dispatching to next-level table at index {start_idx}")
            self.prepare_next(start_idx)
            self.entries[start_idx].map(region.copy(length=(self.chunk - underflow)))
            start_idx = start_idx + 1
            region.length -= self.chunk - underflow
            region.virtaddr += self.chunk - underflow
            region.addr += self.chunk - underflow
            log.debug(f"remaining: {region.length}")
        blocks_allowed = self.level >= (1 if args.tg_str == "4K" else 2)
        num_contiguous_blocks = 0
        num_chunks = region.length // self.chunk
        for i in range(start_idx, start_idx + num_chunks):
            log.debug(f"mapping complete chunk at index {i} {hex(region.addr)}")
            r = region.copy(virtaddr=region.virtaddr, addr=region.addr, length=self.chunk)
            if not blocks_allowed:
                self.prepare_next(i)
                self.entries[i].map(r)
            else:
                self.entries[i] = r
            num_contiguous_blocks += 1
            region.addr += self.chunk
            region.virtaddr += self.chunk
            region.length -= self.chunk
        self.entries[start_idx].num_contig = num_contiguous_blocks
        start_idx += num_chunks;
        overflow = region.length
        if overflow:
            log.debug(f"{overflow=}, dispatching to next-level table at index {start_idx}")
            self.prepare_next(start_idx, region.virtaddr)
            self.entries[start_idx].map(region.copy(addr=region.addr, virtaddr=region.virtaddr, length=overflow))
            region.length -= overflow
        if region.length != 0:
            log.error("Length error: {region.length}")
        log.debug("..")
def map ( self , region : mmap . Region ) -> None : log . debug ( ) log . debug ( f"mapping region {hex(region.virtaddr)}->{hex(region.addr)} in level {self.level} table {self.chunk}" ) log . debug ( region ) assert ( region . virtaddr >= self . va_base ) assert ( region . virtaddr + region . length <= self . va_base + mmu . entries_per_table * self . chunk ) """
        Calculate number of chunks required to map this region.
        A chunk is the area mapped by each individual entry in this table.
        start_idx is the first entry in this table mapping part of the region.
        """ num_chunks = region . length // self . chunk start_idx = ( region . virtaddr // self . chunk ) % mmu . entries_per_table """
        Check whether the region is "floating".
        If so, dispatch to next-level table and we're finished.

                    +--------------------+
                 // |                    |
            Chunk - |####################| <-- Floating region
                 \\ |                    |
                    +--------------------+
        """ if num_chunks == 0 : log . debug ( f"floating region, dispatching to next-level table at index {start_idx}" ) self . prepare_next ( start_idx ) self . entries [ start_idx ] . map ( region ) return """
        Check for any "underflow".
        If so, dispatch the underflow to next-level table and proceed.

                    +--------------------+
                 // |####################|
            Chunk - |####################|
                 \\ |####################|
                    +--------------------+
                 // |####################| <-- Underflow
            Chunk - |                    |
                 \\ |                    |
                    +--------------------+
        """ underflow = region . virtaddr % self . chunk if underflow : log . debug ( f"{underflow=}, dispatching to next-level table at index {start_idx}" ) self . prepare_next ( start_idx ) self . entries [ start_idx ] . map ( region . copy ( length = ( self . chunk - underflow ) ) ) start_idx = start_idx + 1 region . length -= self . chunk - underflow region . virtaddr += self . chunk - underflow region . addr += self . chunk - underflow log . debug ( f"remaining: {region.length}" ) """
        Handle any remaining complete chunks.
        """ blocks_allowed = self . level >= ( 1 if args . tg_str == "4K" else 2 ) num_contiguous_blocks = 0 num_chunks = region . length // self . chunk for i in range ( start_idx , start_idx + num_chunks ) : log . debug ( f"mapping complete chunk at index {i} {hex(region.addr)}" ) r = region . copy ( virtaddr = region . virtaddr , addr = region . addr , length = self . chunk ) if not blocks_allowed : self . prepare_next ( i ) self . entries [ i ] . map ( r ) else : self . entries [ i ] = r num_contiguous_blocks += 1 region . addr += self . chunk region . virtaddr += self . chunk region . length -= self . chunk self . entries [ start_idx ] . num_contig = num_contiguous_blocks start_idx += num_chunks ; """
        Check for any "overflow".
        If so, dispatch the overflow to next-level table and proceed.

                    +--------------------+
                 // |                    |
            Chunk - |                    |
                 \\ |####################| <-- Overflow
                    +--------------------+
                 // |####################|
            Chunk - |####################|
                 \\ |####################|
                    +--------------------+
        """ overflow = region . length if overflow : log . debug ( f"{overflow=}, dispatching to next-level table at index {start_idx}" ) self . prepare_next ( start_idx , region . virtaddr ) self . entries [ start_idx ] . map ( region . copy ( addr = region . addr , virtaddr = region . virtaddr , length = overflow ) ) region . length -= overflow if region . length != 0 : log . error ( "Length error: {region.length}" ) log . debug ( ".." )
Map a region of memory in this translation table.
Map a region of memory in this translation table .
"""
        Map a region of memory in this translation table.
        """ """
        Calculate number of chunks required to map this region.
        A chunk is the area mapped by each individual entry in this table.
        start_idx is the first entry in this table mapping part of the region.
        """ """
        Check whether the region is "floating".
        If so, dispatch to next-level table and we're finished.

                    +--------------------+
                 // |                    |
            Chunk - |####################| <-- Floating region
                 \\ |                    |
                    +--------------------+
        """ """
        Check for any "underflow".
        If so, dispatch the underflow to next-level table and proceed.

                    +--------------------+
                 // |####################|
            Chunk - |####################|
                 \\ |####################|
                    +--------------------+
                 // |####################| <-- Underflow
            Chunk - |                    |
                 \\ |                    |
                    +--------------------+
        """ """
        Handle any remaining complete chunks.
        """ """
        Check for any "overflow".
        If so, dispatch the overflow to next-level table and proceed.

                    +--------------------+
                 // |                    |
            Chunk - |                    |
                 \\ |####################| <-- Overflow
                    +--------------------+
                 // |####################|
            Chunk - |####################|
                 \\ |####################|
                    +--------------------+
        """
self
region
mmap.Region