Changeset ee454eb in mainline


Ignore:
Timestamp:
2006-08-30T15:50:29Z (18 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
beb3926a
Parents:
e11ae91
Message:

sparc64 work.
More bits needed to reach the userspace milestone were added.
The preemptible_handler(), still a prototype, now contains all functionality it needs.
Some sanitation was added to functions expecting page-aligned pointers to
userspace window buffer.

Location:
kernel/arch/sparc64
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/sparc64/include/mm/frame.h

    re11ae91 ree454eb  
    3333 */
    3434
    35 #ifndef __sparc64_FRAME_H__
    36 #define __sparc64_FRAME_H__
     35#ifndef KERN_sparc64_FRAME_H_
     36#define KERN_sparc64_FRAME_H_
    3737
    3838#define FRAME_WIDTH             13      /* 8K */
  • kernel/arch/sparc64/include/mm/page.h

    re11ae91 ree454eb  
    3333 */
    3434
    35 #ifndef __sparc64_PAGE_H__
    36 #define __sparc64_PAGE_H__
     35#ifndef KERN_sparc64_PAGE_H_
     36#define KERN_sparc64_PAGE_H_
    3737
    3838#include <arch/mm/frame.h>
     
    4242
    4343#ifdef KERNEL
     44
     45#ifndef __ASM__
    4446
    4547#include <mm/page.h>
     
    5456        struct {
    5557                uint64_t vpn : 51;              /**< Virtual Page Number. */
    56                 unsigned offset : 13;   /**< Offset. */
     58                unsigned offset : 13;           /**< Offset. */
    5759        } __attribute__ ((packed));
    5860};
     
    6264extern void page_arch_init(void);
    6365
     66#endif /* !def __ASM__ */
     67
    6468#endif /* KERNEL */
    6569
  • kernel/arch/sparc64/include/regdef.h

    re11ae91 ree454eb  
    5050#define TSTATE_CWP_MASK         0x1f
    5151
     52#define WSTATE_NORMAL(n)        (n)
     53#define WSTATE_OTHER(n)         ((n)<<3)
     54
    5255#endif
    5356
  • kernel/arch/sparc64/src/proc/scheduler.c

    re11ae91 ree454eb  
    7979                 */
    8080                ASSERT(THREAD->arch.uspace_window_buffer);
    81                 uintptr_t uw_buf = (uintptr_t) THREAD->arch.uspace_window_buffer;
     81                uintptr_t uw_buf = ALIGN_DOWN((uintptr_t) THREAD->arch.uspace_window_buffer, PAGE_SIZE);
    8282                if (!overlaps(uw_buf, PAGE_SIZE, base, 1<<KERNEL_PAGE_WIDTH)) {
    8383                        /*
    8484                         * The buffer is not covered by the 4M locked kernel DTLB entry.
    8585                         */
    86                         dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, (uintptr_t) uw_buf);
     86                        dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, uw_buf);
    8787                        dtlb_insert_mapping(uw_buf, KA2PA(uw_buf), PAGESIZE_8K, true, true);
    8888                }
     
    127127                flushw();       /* force all userspace windows into memory */
    128128               
    129                 uintptr_t uw_buf = (uintptr_t) THREAD->arch.uspace_window_buffer;
     129                uintptr_t uw_buf = ALIGN_DOWN((uintptr_t) THREAD->arch.uspace_window_buffer, PAGE_SIZE);
    130130                if (!overlaps(uw_buf, PAGE_SIZE, base, 1<<KERNEL_PAGE_WIDTH)) {
    131131                        /*
     
    134134                         * Demap it.
    135135                         */
    136                         dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, (uintptr_t) uw_buf);
     136                        dtlb_demap(TLB_DEMAP_PAGE, TLB_DEMAP_NUCLEUS, uw_buf);
    137137                }
    138138       
  • kernel/arch/sparc64/src/proc/thread.c

    re11ae91 ree454eb  
    3636#include <arch/proc/thread.h>
    3737#include <mm/frame.h>
     38#include <mm/page.h>
     39#include <arch/mm/page.h>
     40#include <align.h>
    3841
    3942void thr_constructor_arch(thread_t *t)
     
    4750void thr_destructor_arch(thread_t *t)
    4851{
    49         if (t->arch.uspace_window_buffer)
    50                 frame_free((uintptr_t) t->arch.uspace_window_buffer);
     52        if (t->arch.uspace_window_buffer) {
     53                /*
     54                 * Mind the possible alignment of the userspace window buffer
     55                 * belonging to a killed thread.
     56                 */
     57                frame_free(ALIGN_DOWN((uintptr_t) t->arch.uspace_window_buffer, PAGE_SIZE));
     58        }
    5159}
    5260
     
    5967                 */
    6068                t->arch.uspace_window_buffer = frame_alloc(ONE_FRAME, 0);
     69        } else {
     70                uintptr_t uw_buf = (uintptr_t) t->arch.uspace_window_buffer;
     71
     72                /*
     73                 * Mind the possible alignment of the userspace window buffer
     74                 * belonging to a killed thread.
     75                 */
     76                 t->arch.uspace_window_buffer = (uint8_t *) ALIGN_DOWN(uw_buf, PAGE_SIZE);
    6177        }
    6278}
  • kernel/arch/sparc64/src/trap/trap_table.S

    re11ae91 ree454eb  
    4141#include <arch/trap/exception.h>
    4242#include <arch/trap/mmu.h>
     43#include <arch/mm/page.h>
    4344#include <arch/stack.h>
    4445#include <arch/regdef.h>
     
    330331
    331332        /*
     333         * Normal window spills will go to the userspace window buffer.
     334         */
     335        wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(2), %wstate
     336
     337        /*
    332338         * Switch to kernel stack. The old stack is
    333339         * automatically saved in the old window's %sp
     
    364370         */
    3653711:
    366 
     372       
     373        /*
     374         * Other window spills will go to the userspace window buffer
     375         * and normal spills will go to the kernel stack.
     376         */
     377        wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(0), %wstate
     378       
    367379        /*
    368380         * Copy arguments.
     
    450462         */
    451463        flushw
    452         mov %sp, %g1
     464        mov %sp, %g2
    453465        stx %i0, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0]
    454466        stx %i1, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1]
     
    460472        stx %i7, [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I7]
    461473        wrpr %l0, 0, %cwp
    462         mov %g1, %sp
     474        mov %g2, %sp
    463475        ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I0], %i0
    464476        ldx [%sp + PREEMPTIBLE_HANDLER_STACK_FRAME_SIZE + STACK_BIAS + SAVED_I1], %i1
     
    472484        /*
    473485         * OTHERWIN != 0 or fall-through from the OTHERWIN == 0 case.
     486         * The CWP has already been restored to the value it had prior to the SAVE
     487         * at the beginning of this function.
    474488         */
    4754890:
    476         ! TODO: restore register windows from register window memory buffer
    477 
     490        rdpr %tstate, %g1
     491        andcc %g1, TSTATE_PRIV_BIT, %g0         ! if we are not returning to userspace...,
     492        bnz 1f                                  ! ...skip restoring userspace windows
     493        nop
     494       
     495        rdpr %cwp, %g1
     496        rdpr %otherwin, %g2
     497
     498        /*
     499         * Skip all OTHERWIN windows and descend to the first window
     500         * in the userspace window buffer.
     501         */
     502        sub %g1, %g2, %g3
     503        dec %g3
     504        and %g3, NWINDOW - 1, %g3
     505        wrpr %g3, 0, %cwp
     506
     507        /*
     508         * CWP is now in the window last saved in the userspace window buffer.
     509         * Fill all windows stored in the buffer.
     510         */
     511        clr %g4
     5120:      andcc %g7, PAGE_WIDTH - 1, %g0          ! PAGE_SIZE alignment check
     513        bz 0f                                   ! %g7 is page-aligned, no more windows to refill
     514        nop
     515
     516        add %g7, -STACK_WINDOW_SAVE_AREA_SIZE, %g7
     517        ldx [%g7 + L0_OFFSET], %l0
     518        ldx [%g7 + L1_OFFSET], %l1
     519        ldx [%g7 + L2_OFFSET], %l2
     520        ldx [%g7 + L3_OFFSET], %l3
     521        ldx [%g7 + L4_OFFSET], %l4
     522        ldx [%g7 + L5_OFFSET], %l5
     523        ldx [%g7 + L6_OFFSET], %l6
     524        ldx [%g7 + L7_OFFSET], %l7
     525        ldx [%g7 + I0_OFFSET], %i0
     526        ldx [%g7 + I1_OFFSET], %i1
     527        ldx [%g7 + I2_OFFSET], %i2
     528        ldx [%g7 + I3_OFFSET], %i3
     529        ldx [%g7 + I4_OFFSET], %i4
     530        ldx [%g7 + I5_OFFSET], %i5
     531        ldx [%g7 + I6_OFFSET], %i6
     532        ldx [%g7 + I7_OFFSET], %i7
     533
     534        dec %g3
     535        and %g3, NWINDOW - 1, %g3
     536        wrpr %g3, 0, %cwp                       ! switch to the preceeding window
     537
     538        ba 0b
     539        inc %g4
     540
     5410:
     542        /*
     543         * Switch back to the proper current window and adjust
     544         * OTHERWIN, CANRESTORE, CANSAVE and CLEANWIN.
     545         */
     546        wrpr %g1, 0, %cwp
     547        add %g4, %g2, %g2
     548        mov NWINDOW - 2, %g1
     549        sub %g1, %g2, %g1
     550       
     551        wrpr %g0, 0, %otherwin
     552        wrpr %g1, 0, %cansave                   ! NWINDOW - 2 - CANRESTORE
     553        wrpr %g2, 0, %canrestore                ! OTHERWIN + windows in the buffer
     554        wrpr %g2, 0, %cleanwin                  ! avoid information leak
     555
     556        /*
     557         * Spills and fills will be processed by the {spill,fill}_1_normal
     558         * handlers.
     559         */
     560        wrpr %g0, WSTATE_OTHER(0) | WSTATE_NORMAL(1), %wstate
     561
     5621:
    478563        restore
    479564        retry
Note: See TracChangeset for help on using the changeset viewer.