Changeset 97f1691 in mainline


Ignore:
Timestamp:
2006-02-28T00:02:39Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7d6ec87
Parents:
d87c3f3
Message:

sparc64 work.
Fix KBD_VIRT_ADDRESS.
Call before_thread_runs() prior to the switch to the thread's stack. Add comment why this is crucial.
Add after_thread_ran() to the scheduler.
Add before_thread_runs_arch() and after_thread_ran_arch() for sparc64, mapping/demapping thread's kernel stack.
Add dummy after_thread_ran_arch() to all other architectures.
Add dtlb_insert_mapping() to promote code reuse.

Files:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • arch/amd64/src/proc/scheduler.c

    rd87c3f3 r97f1691  
    4444        swapgs();
    4545}
     46
     47void after_thread_ran_arch(void)
     48{
     49}
  • arch/ia32/src/proc/scheduler.c

    rd87c3f3 r97f1691  
    3838        CPU->arch.tss->ss0 = selector(KDATA_DES);
    3939}
     40
     41void after_thread_ran_arch(void)
     42{
     43}
  • arch/ia64/src/dummy.s

    rd87c3f3 r97f1691  
    3333.global userspace
    3434.global before_thread_runs_arch
     35.global after_thread_ran_arch
    3536.global cpu_sleep
    3637.global dummy
     
    4041
    4142before_thread_runs_arch:
     43after_thread_ran_arch:
    4244userspace:
    4345calibrate_delay_loop:
  • arch/mips32/src/mips32.c

    rd87c3f3 r97f1691  
    135135        supervisor_sp = (__address) &THREAD->kstack[THREAD_STACK_SIZE-SP_DELTA];
    136136}
     137
     138void after_thread_ran_arch(void)
     139{
     140}
  • arch/ppc32/src/dummy.s

    rd87c3f3 r97f1691  
    3232.global userspace
    3333.global before_thread_runs_arch
     34.global after_thread_ran_arch
    3435.global dummy
    3536.global fpu_init
     
    3839
    3940before_thread_runs_arch:
     41after_thread_ran_arch:
    4042userspace:
    4143asm_delay_loop:
  • arch/sparc64/Makefile.inc

    rd87c3f3 r97f1691  
    8282        arch/$(ARCH)/src/sparc64.c \
    8383        arch/$(ARCH)/src/start.S \
     84        arch/$(ARCH)/src/proc/scheduler.c \
    8485        arch/$(ARCH)/src/trap/trap_table.S \
    8586        arch/$(ARCH)/src/trap/trap.c \
  • arch/sparc64/include/drivers/i8042.h

    rd87c3f3 r97f1691  
    3333
    3434#define KBD_PHYS_ADDRESS        0x1fff8904000ULL
    35 #define KBD_VIRT_ADDRESS        0x00000d00000ULL
     35#define KBD_VIRT_ADDRESS        0x000d0000000ULL
    3636
    3737#define STATUS_REG      4
     
    4141static inline void i8042_data_write(__u8 data)
    4242{
    43         ((__u8 *)(KBD_VIRT_ADDRESS))[DATA_REG] = data;
     43        ((volatile __u8 *)(KBD_VIRT_ADDRESS))[DATA_REG] = data;
    4444}
    4545
     
    5656static inline void i8042_command_write(__u8 command)
    5757{
    58         ((__u8 *)(KBD_VIRT_ADDRESS))[COMMAND_REG] = command;
     58        ((volatile __u8 *)(KBD_VIRT_ADDRESS))[COMMAND_REG] = command;
    5959}
    6060
  • arch/sparc64/include/mm/tlb.h

    rd87c3f3 r97f1691  
    406406extern void fast_data_access_protection(void);
    407407
     408extern void dtlb_insert_mapping(__address page, __address frame, int pagesize, bool locked, bool cacheable);
     409
    408410#endif
  • arch/sparc64/include/trap/exception.h

    rd87c3f3 r97f1691  
    3232#define TT_INSTRUCTION_ACCESS_EXCEPTION         0x08
    3333#define TT_ILLEGAL_INSTRUCTION                  0x10
     34#define TT_DATA_ACCESS_ERROR                    0x32
    3435#define TT_MEM_ADDRESS_NOT_ALIGNED              0x34
    3536
     
    3738extern void do_instruction_access_exc(void);
    3839extern void do_mem_address_not_aligned(void);
     40extern void do_data_access_error(void);
    3941extern void do_illegal_instruction(void);
    4042#endif /* !__ASM__ */
  • arch/sparc64/src/console.c

    rd87c3f3 r97f1691  
    4141#include <proc/thread.h>
    4242#include <synch/mutex.h>
     43#include <arch/mm/tlb.h>
    4344
    4445#define KEYBOARD_POLL_PAUSE     50000   /* 50ms */
     
    7677        ofw_console_active = 0;
    7778        stdin = NULL;
     79
     80        dtlb_insert_mapping(FB_VIRT_ADDRESS, FB_PHYS_ADDRESS, PAGESIZE_4M, true, false);
     81        dtlb_insert_mapping(KBD_VIRT_ADDRESS, KBD_PHYS_ADDRESS, PAGESIZE_8K, true, false);
     82
    7883        fb_init(FB_VIRT_ADDRESS, FB_X_RES, FB_Y_RES, FB_COLOR_DEPTH/8);
    7984        i8042_init();
  • arch/sparc64/src/mm/tlb.c

    rd87c3f3 r97f1691  
    110110        dmmu_enable();
    111111        immu_enable();
    112        
    113         /*
    114          * Quick hack: map frame buffer
    115          */
    116         fr.address = FB_PHYS_ADDRESS;
    117         pg.address = FB_VIRT_ADDRESS;
     112}
     113
     114/** Insert privileged mapping into DMMU TLB.
     115 *
     116 * @param page Virtual page address.
     117 * @param frame Physical frame address.
     118 * @param pagesize Page size.
     119 * @param locked True for permanent mappings, false otherwise.
     120 * @param cacheable True if the mapping is cacheable, false otherwise.
     121 */
     122void dtlb_insert_mapping(__address page, __address frame, int pagesize, bool locked, bool cacheable)
     123{
     124        tlb_tag_access_reg_t tag;
     125        tlb_data_t data;
     126        page_address_t pg;
     127        frame_address_t fr;
     128
     129        pg.address = page;
     130        fr.address = frame;
    118131
    119132        tag.value = ASID_KERNEL;
     
    124137        data.value = 0;
    125138        data.v = true;
    126         data.size = PAGESIZE_4M;
     139        data.size = pagesize;
    127140        data.pfn = fr.pfn;
    128         data.l = true;
    129         data.cp = 0;
    130         data.cv = 0;
     141        data.l = locked;
     142        data.cp = cacheable;
     143        data.cv = cacheable;
    131144        data.p = true;
    132145        data.w = true;
     
    134147
    135148        dtlb_data_in_write(data.value);
    136        
    137         /*
    138          * Quick hack: map keyboard
    139          */
    140         fr.address = KBD_PHYS_ADDRESS;
    141         pg.address = KBD_VIRT_ADDRESS;
    142 
    143         tag.value = ASID_KERNEL;
    144         tag.vpn = pg.vpn;
    145 
    146         dtlb_tag_access_write(tag.value);
    147 
    148         data.value = 0;
    149         data.v = true;
    150         data.size = PAGESIZE_8K;
    151         data.pfn = fr.pfn;
    152         data.l = true;
    153         data.cp = 0;
    154         data.cv = 0;
    155         data.p = true;
    156         data.w = true;
    157         data.g = true;
    158 
    159         dtlb_data_in_write(data.value);
    160149}
    161150
     
    170159{
    171160        tlb_tag_access_reg_t tag;
    172         tlb_data_t data;
    173161        __address tpc;
    174162        char *tpc_str;
     
    187175         * Identity map piece of faulting kernel address space.
    188176         */
    189         data.value = 0;
    190         data.v = true;
    191         data.size = PAGESIZE_8K;
    192         data.pfn = tag.vpn;
    193         data.l = false;
    194         data.cp = 1;
    195         data.cv = 1;
    196         data.p = true;
    197         data.w = true;
    198         data.g = true;
    199 
    200         dtlb_data_in_write(data.value);
     177        dtlb_insert_mapping(tag.vpn * PAGE_SIZE, tag.vpn * FRAME_SIZE, PAGESIZE_8K, false, true);
    201178}
    202179
  • arch/sparc64/src/sparc64.c

    rd87c3f3 r97f1691  
    7575{
    7676}
    77 
    78 void before_thread_runs_arch(void)
    79 {
    80 }
  • arch/sparc64/src/trap/exception.c

    rd87c3f3 r97f1691  
    4343}
    4444
     45/** Handle data_access_error. */
     46void do_data_access_error(void)
     47{
     48        panic("Data Access Error: %P\n", tpc_read());
     49}
     50
    4551/** Handle mem_address_not_aligned. */
    4652void do_illegal_instruction(void)
  • arch/sparc64/src/trap/trap_table.S

    rd87c3f3 r97f1691  
    7373        CLEAN_WINDOW_HANDLER
    7474
     75/* TT = 0x32, TL = 0, data_access_error */
     76.org trap_table + TT_DATA_ACCESS_ERROR*ENTRY_SIZE
     77.global data_access_error
     78data_access_error:
     79        SIMPLE_HANDLER do_data_access_error
     80
    7581/* TT = 0x34, TL = 0, mem_address_not_aligned */
    7682.org trap_table + TT_MEM_ADDRESS_NOT_ALIGNED*ENTRY_SIZE
     
    226232clean_window_handler_high:
    227233        CLEAN_WINDOW_HANDLER
     234
     235/* TT = 0x32, TL > 0, data_access_error */
     236.org trap_table + (TT_DATA_ACCESS_ERROR+512)*ENTRY_SIZE
     237.global data_access_error_high
     238data_access_error_high:
     239        SIMPLE_HANDLER do_data_access_error
    228240
    229241/* TT = 0x34, TL > 0, mem_address_not_aligned */
  • generic/include/proc/scheduler.h

    rd87c3f3 r97f1691  
    5454
    5555extern void before_thread_runs(void);
     56extern void after_thread_ran(void);
    5657
    5758extern void sched_print_list(void);
     59
    5860/*
    5961 * To be defined by architectures:
    6062 */
    61  
    6263extern void before_thread_runs_arch(void);
     64extern void after_thread_ran_arch(void);
    6365
    6466#endif
  • generic/src/proc/scheduler.c

    rd87c3f3 r97f1691  
    5050atomic_t nrdy;
    5151
    52 /** Take actions before new thread runs
     52/** Take actions before new thread runs.
    5353 *
    5454 * Perform actions that need to be
     
    7676        }
    7777#endif
     78}
     79
     80/** Take actions after old thread ran.
     81 *
     82 * Perform actions that need to be
     83 * taken after the running thread
     84 * was preempted by the scheduler.
     85 *
     86 * THREAD->lock is locked on entry
     87 *
     88 */
     89void after_thread_ran(void)
     90{
     91        after_thread_ran_arch();
    7892}
    7993
     
    258272
    259273        if (THREAD) {
     274                /* must be run after switch to scheduler stack */
     275                after_thread_ran();
     276
    260277                switch (THREAD->state) {
    261278                    case Running:
     
    301318                        break;
    302319                }
     320
    303321                THREAD = NULL;
    304322        }
     
    350368        printf("cpu%d: tid %d (priority=%d,ticks=%d,nrdy=%d)\n", CPU->id, THREAD->tid, THREAD->priority, THREAD->ticks, atomic_get(&CPU->nrdy));
    351369        #endif 
     370
     371        /*
     372         * Some architectures provide late kernel PA2KA(identity)
     373         * mapping in a page fault handler. However, the page fault
     374         * handler uses the kernel stack of the running thread and
     375         * therefore cannot be used to map it. The kernel stack, if
     376         * necessary, is to be mapped in before_thread_runs(). This
     377         * function must be executed before the switch to the new stack.
     378         */
     379        before_thread_runs();
    352380
    353381        /*
     
    388416                         * This is the place where threads leave scheduler();
    389417                         */
    390                         before_thread_runs();
    391418                        spinlock_unlock(&THREAD->lock);
    392419                        interrupts_restore(THREAD->saved_context.ipl);
Note: See TracChangeset for help on using the changeset viewer.