Changeset 6c296a9 in mainline


Ignore:
Timestamp:
2008-07-27T13:23:17Z (16 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0d387d2
Parents:
4541ae4
Message:

fix off-by-one bug
cleanup

Location:
kernel/arch/mips32
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/mips32/include/mm/tlb.h

    r4541ae4 r6c296a9  
    5050#define TLB_KSTACK_WIRED_INDEX  0
    5151
    52 #define TLB_PAGE_MASK_16K       (0x3 << 13)
     52#define TLB_PAGE_MASK_4K        (0x000 << 13)
     53#define TLB_PAGE_MASK_16K       (0x003 << 13)
     54#define TLB_PAGE_MASK_64K       (0x00f << 13)
     55#define TLB_PAGE_MASK_256K      (0x03f << 13)
     56#define TLB_PAGE_MASK_1M        (0x0ff << 13)
     57#define TLB_PAGE_MASK_4M        (0x3ff << 13)
     58#define TLB_PAGE_MASK_16M       (0xfff << 13)
    5359
    5460#define PAGE_UNCACHED                   2
  • kernel/arch/mips32/src/mm/frame.c

    r4541ae4 r6c296a9  
    3636#include <arch/mm/frame.h>
    3737#include <arch/mm/tlb.h>
     38#include <interrupt.h>
    3839#include <mm/frame.h>
    3940#include <mm/asid.h>
     
    4243#include <arch/drivers/serial.h>
    4344#include <print.h>
    44 #include <debug.h>
    45 
    46 #define TLB_PAGE_MASK_1M        (0xff << 13)
    47 
     45
     46#define ZERO_PAGE_MASK          TLB_PAGE_MASK_1M
    4847#define ZERO_FRAMES                     4096
    4948#define ZERO_PAGE_WIDTH         20  /* 1M */
     
    5352#define ZERO_PAGE_ADDR          0
    5453#define ZERO_PAGE_OFFSET        (ZERO_PAGE_SIZE / sizeof(uint32_t) - 1)
    55 #define ZERO_PAGE_VALUE         (*((volatile uint32_t *) ZERO_PAGE_ADDR + ZERO_PAGE_OFFSET))
     54#define ZERO_PAGE_VALUE         (((volatile uint32_t *) ZERO_PAGE_ADDR)[ZERO_PAGE_OFFSET])
    5655
    5756#define MAX_REGIONS                     32
     
    132131                /* Convert 1M frames to 16K frames */
    133132                pfn_t first = ADDR2PFN(start_frame << ZERO_PAGE_WIDTH);
    134                 pfn_t count = ADDR2PFN((end_frame - start_frame - 1) << ZERO_PAGE_WIDTH);
     133                pfn_t count = ADDR2PFN((end_frame - start_frame) << ZERO_PAGE_WIDTH);
    135134               
    136135                /* Interrupt vector frame is blacklisted */
     
    157156 * memory and create zones.
    158157 *
     158 * Note: It is assumed that the TLB is not yet being
     159 * used in any way, thus there is no interference.
     160 *
    159161 */
    160162void frame_arch_init(void)
    161163{
    162         cp0_index_write(ZERO_PAGE_TLBI);
    163         tlbr();
    164        
    165         uint32_t orig_pagemask = cp0_pagemask_read();
    166         uint32_t orig_lo0 = cp0_entry_lo0_read();
    167         uint32_t orig_lo1 = cp0_entry_lo1_read();
    168         uint32_t orig_hi = cp0_entry_hi_read();
     164        ipl_t ipl = interrupts_disable();
     165       
     166        /* Clear and initialize TLB */
     167        cp0_pagemask_write(ZERO_PAGE_MASK);
     168        cp0_entry_lo0_write(0);
     169        cp0_entry_lo1_write(0);
     170        cp0_entry_hi_write(0);
     171
     172        count_t i;
     173        for (i = 0; i < TLB_ENTRY_COUNT; i++) {
     174                cp0_index_write(i);
     175                tlbwi();
     176        }
    169177               
    170178        pfn_t start_frame = 0;
     
    185193                                tlb_prepare_entry_hi(&hi, ZERO_PAGE_ASID, ZERO_PAGE_ADDR);
    186194                               
    187                                 cp0_index_write(ZERO_PAGE_TLBI);
    188                                 cp0_pagemask_write(TLB_PAGE_MASK_1M);
     195                                cp0_pagemask_write(ZERO_PAGE_MASK);
    189196                                cp0_entry_lo0_write(lo0.value);
    190197                                cp0_entry_lo1_write(lo1.value);
    191198                                cp0_entry_hi_write(hi.value);
     199                                cp0_index_write(ZERO_PAGE_TLBI);
    192200                                tlbwi();
    193201                               
     
    212220        frame_add_region(start_frame, frame);
    213221       
    214         /* Cleanup TLB */
    215         cp0_index_write(ZERO_PAGE_TLBI);
    216         cp0_pagemask_write(orig_pagemask);
    217         cp0_entry_lo0_write(orig_lo0);
    218         cp0_entry_lo1_write(orig_lo1);
    219         cp0_entry_hi_write(orig_hi);
    220         tlbwi();
    221        
    222222        /* Blacklist interrupt vector frame */
    223223        frame_mark_unavailable(0, 1);
     224       
     225        /* Cleanup */
     226        cp0_pagemask_write(ZERO_PAGE_MASK);
     227        cp0_entry_lo0_write(0);
     228        cp0_entry_lo1_write(0);
     229        cp0_entry_hi_write(0);
     230        cp0_index_write(ZERO_PAGE_TLBI);
     231        tlbwi();
     232       
     233        interrupts_restore(ipl);
    224234}
    225235
Note: See TracChangeset for help on using the changeset viewer.