🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fa.netbsd.tech.kern
Article #123

[Milkymist port] virtual memory management

#123
From: Yann Sionneau
Date: Wed, 29 May 2013 17:51
71 lines
5312 bytes
Hello NetBSD fellows,

As I mentioned in my previous e-mail, I may need from time to time a 
little bit of help since this is my first "full featured OS" port.

I am wondering how I can manage virtual memory (especially how to avoid 
tlb miss, or deal with them) in exception handlers.

At first my idea was to do most of the low level stuff in exception 
handlers with MMU turned off, I was told it was a very bad idea.
LM32 MMU (for now at least) turns itself off upon any CPU exception, 
therefore I plan on turning it on right away in the exception handler.

This leads to the following scenario I don't know how to deal with:

1�) some code somewhere generates an I(nstruction) TLB miss in the MMU, 
this leads to a CPU exception, CPU then branches immediately to the 
"ITLB miss" exception vector.

2�) I turn the MMU back on in the exception vector.

What happens if the virtual address of "TLB miss" exception vector is 
currently not in the ITLB ?
We would "TLB miss" forever in loop, right?

Another scenario: let's assume that I update the ITLB with the 
virtual->physical of the "ITLB miss" exception vector before turning the 
MMU back on.

1�) some code somewhere generates a TLB miss in the MMU, this leads to a 
CPU exception, CPU then branches immediately to the "TLB miss" exception 
vector.

2�) I update the ITLB mapping of the "TLB miss" exception vector.

3�) I do some stuff like loading data from memory or storing data to memory

Then I would hit a D(ata) TLB miss which would generate a CPU exception, 
CPU would branch to "DTLB miss" exception vector.

4�) DTLB exception vector could then generate another DTLB miss 
exception for the same reason (loading from memory or storing to memory)

I am sorry I don't have much documentation to provide about the MMU (it 
is open source hardware though) but I would happily answer any question 
regarding it since I developed most part of it.

It is a very basic MMU, with no hardware page tree walker, it just has 
an ITLB and a DTLB, CPU caches are VIPT (virtually indexed physically 
tagged), I can update a TLB line, flush a line, or flush the entire TLB.

- The MMU can generate 3 types of CPU exceptions: ITLB miss (virtual 
address of fetched instruction not in the ITLB), DTLB miss (virtual 
address of stored/loaded memory location not in the DTLB) and DTLB fault 
(a memory store on a virtual address whose TLB entry is VALID and marked 
as READ-ONLY).

- Software has to take care of all the TLB management (flushing and 
updating TLB).
- The MMU turns itself OFF upon any exception (divide by zero, 
interrupt, bus error, tlb miss, dtlb fault, hardware breakpoint etc).
- The MMU turns itself back to its previous state (the state it has when 
the exception happened) upon execution of "eret" instruction (return 
from exception).

Thank you for your help :)

Cheers!

-- 
Yann Sionneau
Technical Details
Message-ID: <fa.P+LZ+1jPGPfiK1II+UjtSSikPxk@ifi.uio.no>
Path: arc1-ca.pugleaf.net!hv6ni23090wib.1!nntp.google.com!goblin3!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 10c6f4,8afd96964b6c90d9,start
X-Google-NewGroupId: yes
X-Google-Attributes: gidb7e13b6095,domainid0,public,usenet
X-Google-Language: ENGLISH,ASCII
X-Received: by 10.180.76.115 with SMTP id j19mr6749662wiw.2.1369849899324;
        Wed, 29 May 2013 10:51:39 -0700 (PDT)
Path: arc1-ca.pugleaf.net!hv6ni23090wib.1!nntp.google.com!goblin3!goblin1!goblin.stu.neva.ru!uio.no!nntp.uio.no!.POSTED!not-for-mail
From: Yann Sionneau <yann.sionneau@gmail.com>
Newsgroups: fa.netbsd.tech.kern
Subject: [Milkymist port] virtual memory management
Date: Wed, 29 May 2013 17:51:39 UTC
Organization: Internet mailing list
Lines: 71
Sender: tech-kern-owner@NetBSD.org
Message-ID: <fa.P+LZ+1jPGPfiK1II+UjtSSikPxk@ifi.uio.no>
NNTP-Posting-Host: mail-jess.uio.no
Mime-Version: 1.0
X-Trace: readme.uio.no 1369849899 32399 129.240.7.9 (29 May 2013 17:51:39 GMT)
X-Complaints-To: abuse@uio.no
NNTP-Posting-Date: Wed, 29 May 2013 17:51:39 +0000 (UTC)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
Cc: devel@lists.milkymist.org, 
 Radoslaw Kujawa <radoslaw.kujawa@c0ff33.net>
To: tech-kern@netbsd.org
Delivered-To: tech-kern@netbsd.org
X-Virus-Scanned: amavisd-new at NetBSD.org
Authentication-Results: mail.NetBSD.org (amavisd-new);
 dkim=pass (2048-bit key) header.d=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=message-id:date:from:user-agent:mime-version:to:cc:subject
         :content-type:content-transfer-encoding;
        bh=tAucXtZFIOo4yW1F0DVKB6/0Zkgugf+I1/d/zsUMAoc=;
        b=Ngb3DdqGffiHyyfs97ycjVuEmD7XYb9CybrqA6sZC/3hkukkhkPyRzdbo09EtsM1ad
         ypjCx+W5p8cykyct1s2JUHO5D9FwCavn8qSnU3Z9cYiftM/+R50j6FsvzxDAehA3yPBV
         LkLfVYQowRMybtwfFz8kj4B9ywqHSdVMg66ZCWmk+nMx/qZ/8+fYKM4JVXj4xFl4Fh+g
         8R8wFkHMjSnIH29KhXpiIh3r9ThK1hh2IGey6xqrOA28FklzqlasZp4G0sdSAikLKImA
         Kjsl/pIGrzkuSwYYI3jRgR0Y+Oa0gythtFVG4UN8nzRlZyCYJIZhXiMJCMKL8/cNO2LV
         XH9Q==
X-Received: by 10.194.216.105 with SMTP id op9mr2131742wjc.17.1369849877590;
        Wed, 29 May 2013 10:51:17 -0700 (PDT)
List-Id: tech-kern.NetBSD.org
Original-Date: Wed, 29 May 2013 19:51:15 +0200
Original-Message-Id: <51A64013.8030603@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit