Changeset 382fb4ba in mainline


Ignore:
Timestamp:
2013-12-10T22:33:33Z (10 years ago)
Author:
Jakub Klama <jakub.klama@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f7a33de
Parents:
2955bb9
Message:

Fixes as follows:

  • memcpy_from/to_uspace - fixed return value when size is 0
  • saving UWB pointer after thead runs
  • preemptible trap/syscall fixes
  • support for missing page fault types in page_fault()
Location:
kernel/arch/sparc32
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/sparc32/Makefile.inc

    r2955bb9 r382fb4ba  
    4848        arch/$(KARCH)/src/context.S \
    4949        arch/$(KARCH)/src/debug/stacktrace.c \
     50        arch/$(KARCH)/src/debug/stacktrace_asm.S \
    5051        arch/$(KARCH)/src/proc/scheduler.c \
    5152        arch/$(KARCH)/src/proc/task.c \
  • kernel/arch/sparc32/include/arch/interrupt.h

    r2955bb9 r382fb4ba  
    3939#include <arch/istate.h>
    4040
    41 #define IVT_ITEMS  0
     41#define IVT_ITEMS  32
    4242#define IVT_FIRST  0
    4343
  • kernel/arch/sparc32/include/arch/mm/page.h

    r2955bb9 r382fb4ba  
    3737#define KERN_sparc32_PAGE_H_
    3838
     39#ifndef __ASM__
     40
    3941#include <arch/mm/frame.h>
    4042#include <trace.h>
     
    268270#endif
    269271
     272#endif
     273
    270274/** @}
    271275 */
  • kernel/arch/sparc32/src/debug/stacktrace.c

    r2955bb9 r382fb4ba  
    11/*
    22 * Copyright (c) 2010 Jakub Jermar
     3 * Copyright (c) 2013 Jakub Klama
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup abs32le
     30/** @addtogroup sparc32
    3031 * @{
    3132 */
     
    3738#include <typedefs.h>
    3839
     40#include <arch.h>
     41#include <arch/stack.h>
     42
     43#define FRAME_OFFSET_FP_PREV    14
     44#define FRAME_OFFSET_RA         15
     45
     46extern void alloc_window_and_flush(void);
     47
    3948bool kernel_stack_trace_context_validate(stack_trace_context_t *ctx)
    4049{
    41         return true;
     50        uintptr_t kstack;
     51        uint32_t l1, l2;
     52       
     53        read_from_invalid(&kstack, &l1, &l2);
     54        kstack -= 128;
     55
     56        if (THREAD && (ctx->fp == kstack))
     57                return false;
     58        return ctx->fp != 0;
    4259}
    4360
    4461bool kernel_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev)
    4562{
     63        uint64_t *stack = (void *) ctx->fp;
     64        alloc_window_and_flush();
     65        *prev = stack[FRAME_OFFSET_FP_PREV];
    4666        return true;
    4767}
     
    4969bool kernel_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra)
    5070{
     71        uint64_t *stack = (void *) ctx->fp;
     72        alloc_window_and_flush();
     73        *ra = stack[FRAME_OFFSET_RA];
    5174        return true;
    5275}
     
    5477bool uspace_stack_trace_context_validate(stack_trace_context_t *ctx)
    5578{
    56         return true;
     79        return false;
    5780}
    5881
    5982bool uspace_frame_pointer_prev(stack_trace_context_t *ctx, uintptr_t *prev)
    6083{
    61         return true;
     84        return false;
    6285}
    6386
    64 bool uspace_return_address_get(stack_trace_context_t *ctx, uintptr_t *ra)
     87bool uspace_return_address_get(stack_trace_context_t *ctx , uintptr_t *ra)
    6588{
    66         return true;
    67 }
    68 
    69 uintptr_t frame_pointer_get(void)
    70 {
    71         return 0;
    72 }
    73 
    74 uintptr_t program_counter_get(void)
    75 {
    76         return 0;
     89        return false;
    7790}
    7891
  • kernel/arch/sparc32/src/mm/page.c

    r2955bb9 r382fb4ba  
    7474        as_switch(NULL, AS_KERNEL);
    7575
    76         printf("as_context_table=0x%08x\n", as_context_table);
     76//      printf("as_context_table=0x%08x\n", as_context_table);
    7777
    7878        /* Switch MMU to new context table */
     
    8989        mmu_fault_type_t type = (mmu_fault_type_t)fault->at;
    9090
    91         printf("page fault on address 0x%08x, status 0x%08x, type %d\n", fault_address, fault_status, type);
     91//      printf("page fault on address 0x%08x, status 0x%08x, type %d\n", fault_address, fault_status, type);
    9292
    9393        if (type == FAULT_TYPE_LOAD_USER_DATA ||
     
    101101        if (type == FAULT_TYPE_STORE_USER_DATA ||
    102102            type == FAULT_TYPE_STORE_USER_INSTRUCTION ||
    103             type == FAULT_TYPE_STORE_SUPERVISOR_INSTRUCTION)
     103            type == FAULT_TYPE_STORE_SUPERVISOR_INSTRUCTION ||
     104            type == FAULT_TYPE_STORE_SUPERVISOR_DATA)
    104105                as_page_fault(fault_address, PF_ACCESS_WRITE, istate);
    105106}
  • kernel/arch/sparc32/src/proc/scheduler.c

    r2955bb9 r382fb4ba  
    4444void before_thread_runs_arch(void)
    4545{
    46         printf("before_thread_runs_arch(uspace=%d, kernel_sp=0x%08x\n", THREAD->uspace, (uintptr_t)THREAD->kstack + STACK_SIZE);
    4746        if (THREAD->uspace) {
    4847                uint32_t kernel_sp = (uint32_t) THREAD->kstack + STACK_SIZE - 8;
     
    5453void after_thread_ran_arch(void)
    5554{
     55        if (THREAD->uspace) {
     56                uint32_t kernel_sp;
     57                uint32_t uspace_wbuf;
     58                uint32_t l7;
     59                read_from_invalid(&kernel_sp, &uspace_wbuf, &l7);
     60                THREAD->arch.uspace_window_buffer = (uint8_t *)uspace_wbuf;
     61        }
    5662}
    5763
  • kernel/arch/sparc32/src/sparc32.c

    r2955bb9 r382fb4ba  
    165165{
    166166        memcpy(dst, uspace_src, size);
    167         return size;
     167        return 1;
    168168}
    169169
     
    171171{
    172172        memcpy(uspace_dst, src, size);
    173         return size;
     173        return 1;
    174174}
    175175
  • kernel/arch/sparc32/src/trap_table.S

    r2955bb9 r382fb4ba  
    279279        restore
    280280        mov %g5, %wim
     281
     282        /* Check beginning of %sp */
    281283        and %g4, 0xfffff000, %l4
     284        lda [%l4] 0x18, %l4
     285        cmp %l4, 0
     286        bne 1f
     287        nop
     288
     289        /* prepare args for preemptible handler */
     290        mov %g4, %o0
     291        set preemptible_save_uspace, %o2
     292        b preemptible_trap
     293        nop
     294
     295        /* Check end of %sp */
     296        add %g4, 56, %g4
     297        and %l4, 0xfffff000, %l4
    282298        lda [%l4] 0x18, %l4
    283299        cmp %l4, 0
     
    532548        nop
    533549
     550        /* Get UWB address */
     551//      switch_to_invalid %g5, %g6
     552//      mov %l6, %g1
     553//      switch_back %g5, %g6
     554
     555#       /* Flush windows to stack */
     556        call flush_windows
     557        nop
     558/*
     559        get_wim_number %g2
     560        get_cwp %g5
     561        mov %psr, %g6
     562
     563        sub %g2, 1, %g4
     564        and %g4, 0x7, %g4
     5650:      mov %g0, %wim
     566        cmp %g5, %g4
     567        be 0f
     568        nop
     569
     570        restore
     571        add %g1, 64, %g1
     572        std %l0, [%g1  + 0]
     573        std %l2, [%g1 +  8]
     574        std %l4, [%g1 + 16]
     575        std %l6, [%g1 + 24]
     576        std %i0, [%g1 + 32]
     577        std %l2, [%g1 + 40]
     578        std %l4, [%g1 + 48]
     579        std %l6, [%g1 + 56]
     580        inc %g5
     581        and %g5, 0x7, %g5
     582        ba 0b
     583        nop
     584
     5850:      inc %g4
     586        and %g4, 0x7, %g4
     587        clr %g5
     588        inc %g5
     589        sll %g5, %g4, %g5
     590
     591        * Write values to invalid window and switch back *
     592        mov %g7, %l5
     593        mov %g1, %l6
     594        clr %l7
     595        switch_back %g5, %g6
     596*/
     597
    534598        /* Jump to actual subroutine */
    535599        call %o2
     
    548612
    549613        /* If trap originated from uspace, clear uspace window mark and save uwb address for future use */
    550         if_from_kernel 6f
     614        if_from_kernel 9f
    551615        switch_to_invalid %g5, %g6
    552616        clr %l7
     
    594658        switch_back %g5, %g6
    595659
    596         /* If next window is invalid, do inline restore */
    597 6:      get_wim_number %g6
    598         get_cwp %g7
    599         inc %g7
    600         and %g7, 0x7, %g7
    601         cmp %g6, %g7
    602         bne 8f
    603 
    604         if_from_kernel 7f
    605 
    606         inline_restore_uspace %g1
    607         switch_to_invalid %g5, %g6
    608         mov %g1, %l6
    609         switch_back %g5, %g6
    610         b 8f
    611         nop
    612 
    613 7:      inline_restore_kernel
    614 
    615 8:      ld [%sp + 104], %g1
     660        mov %sp, %l3
     661        sub %g2, 128, %sp
     662        ld [%sp + 104], %g1
    616663        ld [%sp + 108], %g2
    617664        ld [%sp + 112], %g3
    618665        ld [%sp + 116], %g4
    619666        ld [%sp + 120], %g7
    620         jmp %l1
     667        mov %l3, %sp
     668        b 10f
     669        nop
     670
     6719:      ld [%sp + 104], %g1
     672        ld [%sp + 108], %g2
     673        ld [%sp + 112], %g3
     674        ld [%sp + 116], %g4
     675        ld [%sp + 120], %g7
     676
     67710:     jmp %l1
    621678        rett %l2
    622679
    623680interrupt_trap:
    624         mov %psr, %l0
    625 
    626         /* Check whether previous mode was usermode */
    627         and %l0, (1 << 6), %l0
    628         cmp %l0, 0
    629         bne 1f
    630         nop
    631 
    632         /* Set up stack */
    633         set kernel_sp, %l4
    634         ld [%l4], %sp
    635         mov %sp, %fp
    636 1:      sub %sp, 112, %sp
    637 
    638         /* Save trap data on stack */
    639         mov %psr, %l0
    640         st %l1, [%fp - 4]
    641         st %l2, [%fp - 8]
    642         st %l0, [%fp - 12]
    643 
    644         /* Enable traps */
    645         mov %psr, %l0
    646         or %l0, (1 << 5), %l0
    647         mov %l0, %psr
    648         nop
    649         nop
    650         nop
    651         nop
    652 
    653         /* Jump to actual subroutine */
    654         mov %g2, %o0
    655         call exc_dispatch
    656         sub %fp, 12, %o1
    657 
    658         /* Return from handler */
    659         ld [%fp - 4], %l1
    660         ld [%fp - 8], %l2
    661         ld [%fp - 12], %l0
    662         mov %l0, %psr
    663         nop
    664         nop
    665         nop
    666         nop
    667         nop
    668 
    669         /* If trap originated from uspace, clear uspace window mark and save uwb address for future use */
    670         if_from_kernel 6f
    671         switch_to_invalid %g5, %g6
    672         clr %l7
    673         mov %l6, %g7
    674         switch_back %g5, %g6
    675         mov %g7, %g1
    676 
    677         /* If next window is invalid, do inline restore */
    678 6:      get_wim_number %g6
    679         get_cwp %g7
    680         inc %g7
    681         cmp %g6, %g7
    682         bne 8f
    683 
    684         if_from_kernel 7f
    685 
    686         inline_restore_uspace %g1
    687         switch_to_invalid %g5, %g6
    688         mov %g1, %l6
    689         switch_back %g5, %g6
    690         b 8f
    691         nop
    692 
    693 7:      inline_restore_kernel
    694 
    695 8:      jmp %l1
    696         rett %l2
    697 
    698 syscall_trap:
    699681        /* Save %g7 */
    700682        mov %g7, %l0
     
    766748        nop
    767749
     750        /* Flush windows to stack */
     751        call flush_windows
     752        nop
     753
    768754        /* Jump to actual subroutine */
    769         sub %o0, 0x80, %o0
    770         st %o0, [ %sp + 92 ]
    771         mov %i0, %o0
    772         mov %i1, %o1
    773         mov %i2, %o2
    774         mov %i3, %o3
    775         mov %i4, %o4
    776         call syscall
    777         mov %i5, %o5
     755        mov %g2, %o0
     756        call exc_dispatch
     757        add %sp, 128, %o1
    778758
    779759        /* Return from handler */
     
    781761        ld [%sp + 96], %l2
    782762        ld [%sp + 100], %l0
    783         mov %o0, %i0
    784         mov %psr, %l1
    785         and %l1, 0xf, %l1
    786         and %l0, 0xfffffff0, %l0
    787         or %l0, %l1, %l0
    788763        mov %l0, %psr
    789764        nop
     
    864839        ld [%sp + 116], %g4
    865840        ld [%sp + 120], %g7
     841        jmp %l1
     842        rett %l2
     843
     844
     845syscall_trap:
     846        /* Save %g7 */
     847        mov %g7, %l0
     848
     849        /* Check whether we landed in invalid window */
     850        get_wim_number %g6
     851        get_cwp %g7
     852        cmp %g6, %g7
     853        bne 4f
     854        nop
     855
     856        /* We are in invalid window. Check whether previous mode was usermode */
     857        if_from_kernel 3f
     858
     859        /* Trap originated from uspace */
     860        /* Kernel stack pointer is at %l5, uwb is at %l6 */
     861        inline_save_uspace %l6
     862
     863        /* set uspace window mark */
     864        mov %psr, %l7
     865        inc %l7
     866        and %l7, 0x7, %l7
     867        or %l7, 0x10, %l7
     868        b 4f
     869        nop
     870
     8713:      /* Trap originated from kernel */
     872        inline_save_kernel
     873
     8744:      /* Check whether previous mode was usermode */
     875        if_from_kernel 5f
     876
     877        /* Load kernel stack pointer from invalid window */
     878        switch_to_invalid %g5, %g6
     879
     880        /* set uspace window mark */
     881        mov %g6, %l7
     882        inc %l7
     883        and %l7, 0x7, %l7
     884        or %l7, 0x10, %l7
     885
     886        /* Save stack pointer */
     887        mov %l5, %g7
     888        switch_back %g5, %g6
     889        mov %g7, %sp
     890//      mov %sp, %fp
     891
     8925:      /* Set up stack frame */
     893        sub %sp, 128, %sp
     894
     895        /* Save trap data on stack */
     896        mov %psr, %l5
     897        st %l1, [%sp + 92]
     898        st %l2, [%sp + 96]
     899        st %l5, [%sp + 100]
     900        st %g1, [%sp + 104]
     901        st %g2, [%sp + 108]
     902        st %g3, [%sp + 112]
     903        st %g4, [%sp + 116]
     904        st %l0, [%sp + 120]
     905
     906        /* Enable traps */
     907        mov %psr, %l0
     908        or %l0, (1 << 5), %l0
     909        mov %l0, %psr
     910        nop
     911        nop
     912        nop
     913        nop
     914
     915        /* Flush windows */
     916        call flush_windows
     917        nop
     918
     919        /* Jump to actual subroutine */
     920        sub %o0, 0x80, %o0
     921        st %o0, [ %sp + 92 ]
     922        mov %i0, %o0
     923        mov %i1, %o1
     924        mov %i2, %o2
     925        mov %i3, %o3
     926        mov %i4, %o4
     927        call syscall
     928        mov %i5, %o5
     929
     930        /* Return from handler */
     931        ld [%sp + 92], %l1
     932        ld [%sp + 96], %l2
     933        ld [%sp + 100], %l0
     934        mov %o0, %i0
     935        mov %psr, %l1
     936        and %l1, 0xf, %l1
     937        and %l0, 0xfffffff0, %l0
     938        or %l0, %l1, %l0
     939        mov %l0, %psr
     940        nop
     941        nop
     942        nop
     943        nop
     944        nop
     945
     946        /* If trap originated from uspace, clear uspace window mark and save uwb address for future use */
     947        if_from_kernel 8f
     948        switch_to_invalid %g5, %g6
     949        mov %l5, %g2
     950        mov %l6, %g1
     951        mov %l7, %g7
     952        switch_back %g5, %g6
     953       
     954        /* If trap originated from uspace, restore all windows from UWB */
     955        /* UWB pointer is at %g1 */
     9560:      mov %g0, %wim
     957        clr %g5
     958        andcc %g1, UWB_ALIGNMENT - 1, %g0
     959        bz 0f
     960        nop
     961
     962        restore
     963        sub %g1, 64, %g1
     964        ldd [%g1 +  0], %l0
     965        ldd [%g1 +  8], %l2
     966        ldd [%g1 + 16], %l4
     967        ldd [%g1 + 24], %l6
     968        ldd [%g1 + 32], %i0
     969        ldd [%g1 + 40], %i2
     970        ldd [%g1 + 48], %i4
     971        ldd [%g1 + 56], %i6
     972        inc %g5
     973        and %g5, 0x7, %g5
     974        ba 0b
     975        nop
     976
     977        /* We've restored all uspace windows. Now time to
     978         * fix CWP and WIM
     979         */
     9800:      restore
     981        get_cwp %g7
     982        clr %g5
     983        inc %g5
     984        sll %g5, %g7, %g5
     985
     986        /* Write values to invalid window and switch back */
     987        mov %g2, %l5
     988        mov %g1, %l6
     989        clr %l7
     990        switch_back %g5, %g6
     991
     9928:      mov %sp, %l1
     993        sub %g2, 128, %sp
     994        ld [%sp + 104], %g1
     995        ld [%sp + 108], %g2
     996        ld [%sp + 112], %g3
     997        ld [%sp + 116], %g4
     998        ld [%sp + 120], %g7
     999        mov %l1, %sp
    8661000        jmp %l2
    8671001        rett %l2 + 4
Note: See TracChangeset for help on using the changeset viewer.