9os

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit fcc54cb0d2de6d363e9bcf39d085ddc61960c451
parent d120ce85422a76ce88a6f9be7d5123bc42bb21b5
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  1 Nov 2020 10:00:03 +0100

os9/arm64: Convert between physical and virtual mem

When we deal with the page table we have to be careful of
transforming between physical and virtual memory.

Change-Id: If8999b5d837d92c390d2f886e3847b33eabea987

Diffstat:
Minclude/os9/os9.h | 2++
Msrc/os9/arch/arm64/mmu.c | 22+++++++++++++---------
Msrc/os9/arch/arm64/trap.c | 2+-
3 files changed, 16 insertions(+), 10 deletions(-)

diff --git a/include/os9/os9.h b/include/os9/os9.h @@ -24,6 +24,8 @@ #define MiB (1024u * KiB) #define GiB (1024ul * MiB) +#define VMEM(x) ((void *) ((char *) (x) + mach.kzero)) +#define PMEM(x) ((void *) ((char *) (x) - mach.kzero)) #define PAGESIZE (4 * KiB) #define ENABLE 1 #define DISABLE 0 diff --git a/src/os9/arch/arm64/mmu.c b/src/os9/arch/arm64/mmu.c @@ -139,13 +139,16 @@ int inlowmem = 1; static pte_t -newpage(void) +newtable(void) { - void *bp; + char *bp; bp = allocb(1); memset(bp, 0, PAGESIZE); + if (!inlowmem) + bp = PMEM(bp); + return (pte_t) bp; } @@ -165,11 +168,13 @@ walker(uintptr_t va) e = bp[n]; if (e == INVALID) { - e = newpage(); + e = newtable(); bp[n] = e | TABLE; barrier(DATA); } bp = (pte_t *) MASK(e); + if (!inlowmem) + bp = VMEM(bp); } return &bp[TINDEX(3, va)]; @@ -237,12 +242,11 @@ mapseg(Map *mp) pa = mp->pa; va = mp->va; - n = (mp->siz + 4*KiB-1)/(4*KiB); - + n = (mp->siz + PAGESIZE-1)/PAGESIZE; for (i = 0; i < n; i++) { vmap(pa, va, mp->perm); - pa += 4*KiB; - va += 4*KiB; + pa += PAGESIZE; + va += PAGESIZE; } } @@ -278,7 +282,7 @@ kernelmap(void) * FIXME: We are using a full page when * we only need 16 bytes with 16 byte alignment. */ - syswr(TTBR1_EL1, newpage()); + syswr(TTBR1_EL1, newtable()); dbg("TTBR1_EL1=%llx\n", sysrd(TTBR1_EL1)); @@ -302,7 +306,7 @@ initmap(void) syswr(TCR_EL1, tcr); barrier(CODE); - tbl = newpage(); + tbl = newtable(); bp = (pte_t *) tbl; for (pa = 0; pa < 4*GiB; pa += 1*GiB) *bp++ = pa | attr; diff --git a/src/os9/arch/arm64/trap.c b/src/os9/arch/arm64/trap.c @@ -24,7 +24,7 @@ trap(Context *ctx) if (ec != SVC || inlowmem) { msg = (ec < NR_EC_VALS) ? ecstr[ec] : "unknown reason"; if (inlowmem) - msg -= mach.kzero; + msg = PMEM(msg); fault(msg, ctx); }