Changeset 1084a784 in mainline for arch/mips32/src


Ignore:
Timestamp:
2005-10-04T22:09:41Z (20 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
342de62
Parents:
8e3f47b3
Message:

mips32 memory management work.
TLB Refill Exception implemented (passed basic testing).
Remove bit g from struct entry_hi.
Add generic find_mapping().
Add asid to vm_t type, define asid_t to hide architecture specific differences.
Implement ASID allocation for mips32, dummy for other architectures.
Add THE→vm (a.k.a. VM).
Add vm_install_arch().
Move pte_t definition to arch/types.h on each architecture.
Fix PTL manipulating functions on mips32 to shift pfn by 12 instead of by 14.
Fix tlb_init_arch() to initialize all entries.

Other.
Remove unnecessary header files from arch.h
Add missing headers here and there.
Remove two unnecessary ld flags from mips32 makefile.

Location:
arch/mips32/src
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • arch/mips32/src/exception.c

    r8e3f47b3 r1084a784  
    3434#include <arch.h>
    3535#include <debug.h>
     36#include <proc/thread.h>
    3637
    3738void exception(struct exception_regdump *pstate)
  • arch/mips32/src/mips32.c

    r8e3f47b3 r1084a784  
    3838#include <arch/interrupt.h>
    3939#include <arch/drivers/arc.h>
    40 
     40#include <proc/thread.h>
    4141#include <print.h>
    4242
  • arch/mips32/src/mm/asid.c

    r8e3f47b3 r1084a784  
    2727 */
    2828
     29#include <arch/mm/asid.h>
     30#include <synch/spinlock.h>
    2931#include <arch.h>
    30 #include <memstr.h>
     32#include <debug.h>
    3133
    32 /**< Array of threads that have currently some ASID assigned,
    33      NULL means no thread have ASID with number of that index assigned */
    34 struct thread * asids[256];
    35 int last_asid; /**< The number of last assigned ASID */
    36 int asid_bitmap[32]; /**< Bitmap of ASIDs currently in TLB */
     34#define ASIDS   256
    3735
     36static spinlock_t asid_usage_lock;
     37static count_t asid_usage[ASIDS];       /**< Usage tracking array for ASIDs */
    3838
    39 /** Cleanup asid_bitmap
     39/** Get ASID
    4040 *
     41 * Get the least used ASID.
     42 *
     43 * @return ASID
    4144 */
    42 void asid_bitmap_reset(void)
     45asid_t asid_get(void)
    4346{
    44         memsetb(asid_bitmap, sizeof(asid_bitmap), 0);
     47        pri_t pri;
     48        int i, j;
     49        count_t min;
     50       
     51        min = (unsigned) -1;
     52       
     53        pri = cpu_priority_high();
     54        spinlock_lock(&asid_usage_lock);
     55       
     56        for (i=0, j = 0; (i<ASIDS); i++) {
     57                if (asid_usage[i] < min) {
     58                        j = i;
     59                        min = asid_usage[i];
     60                        if (!min)
     61                                break;
     62                }
     63        }
     64
     65        asid_usage[i]++;
     66
     67        spinlock_unlock(&asid_usage_lock);
     68        cpu_priority_restore(pri);
     69
     70        return i;
    4571}
    4672
     73/** Release ASID
     74 *
     75 * Release ASID by decrementing its usage count.
     76 *
     77 * @param asid ASID.
     78 */
     79void asid_put(asid_t asid)
     80{
     81        pri_t pri;
    4782
    48 /** Initialize manipulating with ASIDs
    49  *
    50  */
    51 void init_asids(void)
    52 {
    53         memsetb(asids, sizeof(asids), 0);
    54         asid_bitmap_reset();
    55         last_asid = 0;
     83        pri = cpu_priority_high();
     84        spinlock_lock(&asid_usage_lock);
     85
     86        ASSERT(asid_usage[asid] > 0);
     87        asid_usage[asid]--;
     88
     89        spinlock_unlock(&asid_usage_lock);
     90        cpu_priority_restore(pri);
    5691}
  • arch/mips32/src/mm/tlb.c

    r8e3f47b3 r1084a784  
    3030#include <arch/mm/asid.h>
    3131#include <mm/tlb.h>
     32#include <mm/page.h>
     33#include <mm/vm.h>
    3234#include <arch/cp0.h>
    3335#include <panic.h>
    3436#include <arch.h>
    3537#include <symtab.h>
     38#include <synch/spinlock.h>
     39#include <print.h>
    3640
     41static void tlb_refill_fail(struct exception_regdump *pstate);
     42static void tlb_invalid_fail(struct exception_regdump *pstate);
     43static void tlb_modified_fail(struct exception_regdump *pstate);
     44
     45/** Initialize TLB
     46 *
     47 * Initialize TLB.
     48 * Invalidate all entries and mark wired entries.
     49 */
    3750void tlb_init_arch(void)
    3851{
     
    4861         */
    4962        for (i = 0; i < TLB_SIZE; i++) {
    50                 cp0_index_write(0);
     63                cp0_index_write(i);
    5164                tlbwi();
    5265        }
     
    5467        /*
    5568         * The kernel is going to make use of some wired
    56          * entries (e.g. mapping kernel stacks).
     69         * entries (e.g. mapping kernel stacks in kseg3).
    5770         */
    5871        cp0_wired_write(TLB_WIRED);
    5972}
    6073
     74/** Process TLB Refill Exception
     75 *
     76 * Process TLB Refill Exception.
     77 *
     78 * @param pstate Interrupted register context.
     79 */
    6180void tlb_refill(struct exception_regdump *pstate)
     81{
     82        struct entry_hi hi;
     83        __address badvaddr;
     84        pte_t *pte;
     85       
     86        *((__u32 *) &hi) = cp0_entry_hi_read();
     87        badvaddr = cp0_badvaddr_read();
     88       
     89        spinlock_lock(&VM->lock);
     90
     91        /*
     92         * Refill cannot succeed if the ASIDs don't match.
     93         */
     94        if (hi.asid != VM->asid)
     95                goto fail;
     96
     97        /*
     98         * Refill cannot succeed if badvaddr is not
     99         * associated with any mapping.
     100         */
     101        pte = find_mapping(badvaddr, 0);
     102        if (!pte)
     103                goto fail;
     104               
     105        /*
     106         * Refill cannot succeed if the mapping is marked as invalid.
     107         */
     108        if (!pte->v)
     109                goto fail;
     110
     111        /*
     112         * New entry is to be inserted into TLB
     113         */
     114        cp0_pagemask_write(TLB_PAGE_MASK_16K);
     115        if ((badvaddr/PAGE_SIZE) % 2 == 0) {
     116                cp0_entry_lo0_write(*((__u32 *) pte));
     117                cp0_entry_lo1_write(0);
     118        }
     119        else {
     120                cp0_entry_lo0_write(0);
     121                cp0_entry_lo1_write(*((__u32 *) pte));
     122        }
     123        tlbwr();
     124
     125        spinlock_unlock(&VM->lock);
     126        return;
     127       
     128fail:
     129        spinlock_unlock(&VM->lock);
     130        tlb_refill_fail(pstate);
     131}
     132
     133void tlb_invalid(struct exception_regdump *pstate)
     134{
     135        tlb_invalid_fail(pstate);
     136}
     137
     138void tlb_modified(struct exception_regdump *pstate)
     139{
     140        tlb_modified_fail(pstate);
     141}
     142
     143void tlb_refill_fail(struct exception_regdump *pstate)
    62144{
    63145        char *symbol = "";
     
    70152        if (s)
    71153                sym2 = s;
    72         panic("%X: TLB Refill Exception at %X(%s<-%s)\n", cp0_badvaddr_read(),
    73               pstate->epc, symbol, sym2);
     154        panic("%X: TLB Refill Exception at %X(%s<-%s)\n", cp0_badvaddr_read(), pstate->epc, symbol, sym2);
    74155}
    75156
    76 void tlb_invalid(struct exception_regdump *pstate)
     157
     158void tlb_invalid_fail(struct exception_regdump *pstate)
    77159{
    78160        char *symbol = "";
     
    85167}
    86168
    87 void tlb_modified(struct exception_regdump *pstate)
     169void tlb_modified_fail(struct exception_regdump *pstate)
    88170{
    89171        char *symbol = "";
     
    103185        pri = cpu_priority_high();
    104186       
    105 //      asid_bitmap_reset();
    106        
    107187        // TODO
    108188       
Note: See TracChangeset for help on using the changeset viewer.