Changeset cfa70add in mainline for uspace


Ignore:
Timestamp:
2006-09-03T23:37:14Z (19 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fd85ae5
Parents:
002e613
Message:

sparc64 update.

  • Prototype userspace layer implementation that at least relates to sparc64 and compiles cleanly.
  • Fixes for kernel's preemptible_handler and code related to running userspace.
  • Enable userspace. Several dozen instructions are now run in userspace! We are pretty near the userspace milestone for sparc64.
Location:
uspace/libc/arch/sparc64
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • uspace/libc/arch/sparc64/_link.ld.in

    r002e613 rcfa70add  
    88
    99SECTIONS {
    10         . = 0x1000;
     10        . = 0x2000;
    1111
    12         .init ALIGN(0x1000) : SUBALIGN(0x1000) {
     12        .init ALIGN(0x2000) : SUBALIGN(0x2000) {
    1313                *(.init);
    1414        } :text
     
    1818        } :text
    1919       
    20         .data ALIGN(0x1000) : SUBALIGN(0x1000) {
     20        .got ALIGN(0x2000) : SUBALIGN(0x2000) {
     21                 _gp = .;
     22                 *(.got*);
     23        } :data
     24        .data ALIGN(0x2000) : SUBALIGN(0x2000) {
    2125                *(.data);
    2226                *(.sdata);
     
    3842        } :data
    3943
    40         . = ALIGN(0x1000);
     44        . = ALIGN(0x2000);
    4145        _heap = .;
    4246       
  • uspace/libc/arch/sparc64/include/atomic.h

    r002e613 rcfa70add  
    11/*
    2  * Copyright (C) 2005 Martin Decky
     2 * Copyright (C) 2005 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libcsparc64     
     29/** @addtogroup libcsparc64
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef __sparc64_ATOMIC_H__
    36 #define __sparc64_ATOMIC_H__
     35#ifndef LIBC_sparc64_ATOMIC_H_
     36#define LIBC_sparc64_ATOMIC_H_
     37
     38#include <types.h>
     39
     40/** Atomic add operation.
     41 *
     42 * Use atomic compare and swap operation to atomically add signed value.
     43 *
     44 * @param val Atomic variable.
     45 * @param i Signed value to be added.
     46 *
     47 * @return Value of the atomic variable as it existed before addition.
     48 */
     49static inline long atomic_add(atomic_t *val, int i)
     50{
     51        uint64_t a, b;
     52        volatile uint64_t x = (uint64_t) &val->count;
     53
     54        __asm__ volatile (
     55                "0:\n"
     56                "ldx %0, %1\n"
     57                "add %1, %3, %2\n"
     58                "casx %0, %1, %2\n"
     59                "cmp %1, %2\n"
     60                "bne 0b\n"              /* The operation failed and must be attempted again if a != b. */
     61                "nop\n"
     62                : "=m" (*((uint64_t *)x)), "=r" (a), "=r" (b)
     63                : "r" (i)
     64        );
     65
     66        return a;
     67}
     68
     69static inline long atomic_preinc(atomic_t *val)
     70{
     71        return atomic_add(val, 1) + 1;
     72}
     73
     74static inline long atomic_postinc(atomic_t *val)
     75{
     76        return atomic_add(val, 1);
     77}
     78
     79static inline long atomic_predec(atomic_t *val)
     80{
     81        return atomic_add(val, -1) - 1;
     82}
     83
     84static inline long atomic_postdec(atomic_t *val)
     85{
     86        return atomic_add(val, -1);
     87}
    3788
    3889static inline void atomic_inc(atomic_t *val)
    3990{
     91        (void) atomic_add(val, 1);
    4092}
    4193
    4294static inline void atomic_dec(atomic_t *val)
    4395{
    44 }
    45 
    46 static inline long atomic_postinc(atomic_t *val)
    47 {
    48         atomic_inc(val);
    49         return val->count - 1;
    50 }
    51 
    52 static inline long atomic_postdec(atomic_t *val)
    53 {
    54         atomic_dec(val);
    55         return val->count + 1;
    56 }
    57 
    58 static inline long atomic_preinc(atomic_t *val)
    59 {
    60         atomic_inc(val);
    61         return val->count;
    62 }
    63 
    64 static inline long atomic_predec(atomic_t *val)
    65 {
    66         atomic_dec(val);
    67         return val->count;
     96        (void) atomic_add(val, -1);
    6897}
    6998
  • uspace/libc/arch/sparc64/include/config.h

    r002e613 rcfa70add  
    2727 */
    2828
    29 /** @addtogroup libsparc64
     29/** @addtogroup libcsparc64
    3030 * @{
    3131 */
     
    3636#define LIBC_sparc64_CONFIG_H_
    3737
    38 #define PAGE_WIDTH      12
     38#define PAGE_WIDTH      13
    3939#define PAGE_SIZE       (1<<PAGE_WIDTH)
    4040
  • uspace/libc/arch/sparc64/include/context_offset.h

    r002e613 rcfa70add  
     1/* This file is automatically generated by gencontext.c. */
    12/* struct context */
     3#define OFFSET_SP       0x0
     4#define OFFSET_PC       0x8
     5#define OFFSET_I0       0x10
     6#define OFFSET_I1       0x18
     7#define OFFSET_I2       0x20
     8#define OFFSET_I3       0x28
     9#define OFFSET_I4       0x30
     10#define OFFSET_I5       0x38
     11#define OFFSET_FP       0x40
     12#define OFFSET_I7       0x48
     13#define OFFSET_L0       0x50
     14#define OFFSET_L1       0x58
     15#define OFFSET_L2       0x60
     16#define OFFSET_L3       0x68
     17#define OFFSET_L4       0x70
     18#define OFFSET_L5       0x78
     19#define OFFSET_L6       0x80
     20#define OFFSET_L7       0x88
     21#define OFFSET_TP       0x90
    222
    3 /** @}
    4  */
  • uspace/libc/arch/sparc64/include/endian.h

    r002e613 rcfa70add  
    2727 */
    2828
    29  /** @addtogroup libcsparc64   
     29/** @addtogroup libcsparc64     
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef __sparc64_ENDIAN_H__
    36 #define __sparc64_ENDIAN_H__
     35#ifndef LIBC_sparc64_ENDIAN_H_
     36#define LIBC_sparc64_ENDIAN_H_
    3737
    3838#ifndef __LIBC__ENDIAN_H__
     
    4444#endif
    4545
    46  /** @}
     46/** @}
    4747 */
    48 
  • uspace/libc/arch/sparc64/include/limits.h

    r002e613 rcfa70add  
    3333 */
    3434
    35 #ifndef __sparc64__LIMITS_H__
    36 #define __sparc64__LIMITS_H__
     35#ifndef LIBC_sparc64__LIMITS_H_
     36#define LIBC_sparc64__LIMITS_H_
    3737
    3838#define LONG_MIN MIN_INT64
  • uspace/libc/arch/sparc64/include/psthread.h

    r002e613 rcfa70add  
    11/*
    2  * Copyright (C) 2006 Martin Decky
     2 * Copyright (C) 2005 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    2727 */
    2828
    29 /** @addtogroup libcsparc64     
     29/** @addtogroup libcsparc64
    3030 * @{
    3131 */
     
    3333 */
    3434
    35 #ifndef __LIBC__sparc64__PSTHREAD_H__
    36 #define __LIBC__sparc64__PSTHREAD_H__
     35#ifndef LIBC_sparc64_PSTHREAD_H_
     36#define LIBC_sparc64_PSTHREAD_H_
    3737
     38#include <libarch/stack.h>
    3839#include <types.h>
     40#include <align.h>
    3941
    40 /* We define our own context_set, because we need to set
    41  * the TLS pointer to the tcb+0x7000
    42  *
    43  * See tls_set in thread.h
     42#define SP_DELTA        STACK_WINDOW_SAVE_AREA_SIZE
     43
     44#ifdef context_set
     45#undef context_set
     46#endif
     47
     48#define context_set(c, _pc, stack, size, ptls)                                                          \
     49        (c)->pc = ((uintptr_t) _pc) - 8;                                                                \
     50        (c)->sp = ((uintptr_t) stack) + ALIGN_UP((size), STACK_ALIGNMENT) - (STACK_BIAS + SP_DELTA);    \
     51        (c)->fp = -STACK_BIAS;                                                                          \
     52        (c)->tp = ptls
     53       
     54/*
     55 * Only save registers that must be preserved across
     56 * function calls.
    4457 */
    45 #define context_set(c, _pc, stack, size, ptls)                  \
    46         (c)->pc = (sysarg_t) (_pc);                             \
    47         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    48         (c)->tls = ((sysarg_t) (ptls)) + 0x7000 + sizeof(tcb_t);
    49 
    50 #define SP_DELTA        16
    51 
    5258typedef struct {
    53         uint64_t sp;
    54         uint64_t pc;
    55        
    56         uint64_t tls;
    57 } __attribute__ ((packed)) context_t;
     59        uintptr_t sp;           /* %o6 */
     60        uintptr_t pc;           /* %o7 */
     61        uint64_t i0;
     62        uint64_t i1;
     63        uint64_t i2;
     64        uint64_t i3;
     65        uint64_t i4;
     66        uint64_t i5;
     67        uintptr_t fp;           /* %i6 */
     68        uintptr_t i7;
     69        uint64_t l0;
     70        uint64_t l1;
     71        uint64_t l2;
     72        uint64_t l3;
     73        uint64_t l4;
     74        uint64_t l5;
     75        uint64_t l6;
     76        uint64_t l7;
     77        uint64_t tp;            /* %g7 */
     78} context_t;
    5879
    5980#endif
  • uspace/libc/arch/sparc64/include/stackarg.h

    r002e613 rcfa70add  
    3333 */
    3434
    35 #ifndef __LIBC__STACKARG_H__
    36 #define __LIBC__STACKARG_H__
     35#ifndef LIBC_sparc64_STACKARG_H_
     36#define LIBC_sparc64_STACKARG_H_
    3737
    3838#endif
    3939
    40 
    4140/** @}
    4241 */
  • uspace/libc/arch/sparc64/include/syscall.h

    r002e613 rcfa70add  
    2727 */
    2828
    29 /** @addtogroup libc
     29/** @addtogroup libcsparc64
    3030 * @{
    3131 */
  • uspace/libc/arch/sparc64/include/thread.h

    r002e613 rcfa70add  
    11/*
    2  * Copyright (C) 2006 Martin Decky
     2 * Copyright (C) 2006 Ondrej Palkovsky
     3 * Copyright (C) 2006 Jakub Jermar
    34 * All rights reserved.
    45 *
     
    2728 */
    2829
    29 /** @addtogroup libcsparc64     
     30/** @addtogroup libcsparc64
    3031 * @{
    3132 */
    32 /** @file
     33/**
     34 * @file
     35 * @brief       sparc64 TLS functions.
     36 *
     37 * The implementation is based on the IA-32 implementation which was also
     38 * designed by Sun and is virtually the same, except the TCB is stored in
     39 * %g7 (of the normal set).
    3340 */
    3441
    35 #ifndef __LIBC__sparc64__THREAD_H__
    36 #define __LIBC__sparc64__THREAD_H__
    37 
    38 #define PPC_TP_OFFSET 0x7000
     42#ifndef LIBC_sparc64_THREAD_H_
     43#define LIBC_sparc64_THREAD_H_
    3944
    4045typedef struct {
     46        void *self;
    4147        void *pst_data;
    4248} tcb_t;
     
    4450static inline void __tcb_set(tcb_t *tcb)
    4551{
    46         void *tp = tcb;
    47         tp += PPC_TP_OFFSET + sizeof(tcb_t);
     52        __asm__ volatile ("mov %0, %%g7\n" : : "r" (tcb) : "g7");
    4853}
    4954
    50 static inline tcb_t *__tcb_get(void)
     55static inline tcb_t * __tcb_get(void)
    5156{
    52         return (tcb_t *)(PPC_TP_OFFSET - sizeof(tcb_t));
     57        void *retval;
     58
     59        __asm__ volatile ("mov %%g7, %0\n" : "=r" (retval));
     60
     61        return retval;
    5362}
    5463
  • uspace/libc/arch/sparc64/include/types.h

    r002e613 rcfa70add  
    3636#define LIBC_sparc64_TYPES_H_
    3737
    38 typedef unsigned int sysarg_t;
    39 typedef unsigned int size_t;
    40 typedef signed int ssize_t;
     38typedef unsigned long sysarg_t;
     39typedef unsigned long size_t;
     40typedef signed long ssize_t;
    4141typedef ssize_t off_t;
    4242
    43 typedef char int8_t;
     43typedef signed char int8_t;
    4444typedef short int int16_t;
    4545typedef int int32_t;
  • uspace/libc/arch/sparc64/src/entry.s

    r002e613 rcfa70add  
    3838#
    3939__entry:
     40        sethi %hi(_gp), %l7
     41        call __main
     42        or %l7, %lo(_gp), %l7
     43        call __io_init
     44        nop
     45        call main
     46        nop
     47        call __exit
     48        nop
    4049
    4150__entry_driver:
     51        sethi %hi(_gp), %l7
     52        call __main
     53        or %l7, %lo(_gp), %l7
     54        call main
     55        nop
     56        call __exit
     57        nop
  • uspace/libc/arch/sparc64/src/psthread.S

    r002e613 rcfa70add  
    11#
    2 # Copyright (C) 2006 Martin Decky
     2# Copyright (C) 2005 Jakub Jermar
    33# All rights reserved.
    44#
     
    2727#
    2828
    29 .text
     29#include <libarch/context_offset.h>
     30
     31/**
     32 * Both context_save_arch() and context_restore_arch() are
     33 * leaf-optimized procedures. This kind of optimization
     34 * is very important and prevents any implicit window
     35 * spill/fill/clean traps in these very core kernel
     36 * functions.
     37 */
     38       
     39.text   
    3040
    3141.global context_save
    3242.global context_restore
    3343
    34 #include <libarch/context_offset.h>
     44.macro CONTEXT_STORE r
     45        stx %sp, [\r + OFFSET_SP]
     46        stx %o7, [\r + OFFSET_PC]
     47        stx %i0, [\r + OFFSET_I0]
     48        stx %i1, [\r + OFFSET_I1]
     49        stx %i2, [\r + OFFSET_I2]
     50        stx %i3, [\r + OFFSET_I3]
     51        stx %i4, [\r + OFFSET_I4]
     52        stx %i5, [\r + OFFSET_I5]
     53        stx %fp, [\r + OFFSET_FP]
     54        stx %i7, [\r + OFFSET_I7]
     55        stx %l0, [\r + OFFSET_L0]
     56        stx %l1, [\r + OFFSET_L1]
     57        stx %l2, [\r + OFFSET_L2]
     58        stx %l3, [\r + OFFSET_L3]
     59        stx %l4, [\r + OFFSET_L4]
     60        stx %l5, [\r + OFFSET_L5]
     61        stx %l6, [\r + OFFSET_L6]
     62        stx %l7, [\r + OFFSET_L7]
     63        stx %g7, [\r + OFFSET_TP]
     64.endm
     65
     66.macro CONTEXT_LOAD r
     67        ldx [\r + OFFSET_SP], %sp
     68        ldx [\r + OFFSET_PC], %o7
     69        ldx [\r + OFFSET_I0], %i0
     70        ldx [\r + OFFSET_I1], %i1
     71        ldx [\r + OFFSET_I2], %i2
     72        ldx [\r + OFFSET_I3], %i3
     73        ldx [\r + OFFSET_I4], %i4
     74        ldx [\r + OFFSET_I5], %i5
     75        ldx [\r + OFFSET_FP], %fp
     76        ldx [\r + OFFSET_I7], %i7
     77        ldx [\r + OFFSET_L0], %l0
     78        ldx [\r + OFFSET_L1], %l1
     79        ldx [\r + OFFSET_L2], %l2
     80        ldx [\r + OFFSET_L3], %l3
     81        ldx [\r + OFFSET_L4], %l4
     82        ldx [\r + OFFSET_L5], %l5
     83        ldx [\r + OFFSET_L6], %l6
     84        ldx [\r + OFFSET_L7], %l7
     85        ldx [\r + OFFSET_TP], %g7
     86.endm
    3587
    3688context_save:
    37 
     89        CONTEXT_STORE %o0
     90        retl
     91        mov 1, %o0              ! context_save_arch returns 1
    3892
    3993context_restore:
     94        #
     95        # Flush all active windows.
     96        # This is essential, because CONTEXT_LOAD overwrites
     97        # %sp of CWP - 1 with the value written to %fp of CWP.
     98        # Flushing all active windows mitigates this problem
     99        # as CWP - 1 becomes the overlap window.
     100        #               
     101        flushw
     102       
     103        CONTEXT_LOAD %o0
     104        retl
     105        xor %o0, %o0, %o0       ! context_restore_arch returns 0
  • uspace/libc/arch/sparc64/src/thread.c

    r002e613 rcfa70add  
    2727 */
    2828
    29 /** @addtogroup libcsparc64     
     29/** @addtogroup libcsparc64 sparc64
     30 * @ingroup lc
    3031 * @{
    3132 */
    3233/** @file
     34 *
    3335 */
    3436
     
    4042 * @param data Start of data section
    4143 * @return pointer to tcb_t structure
    42  *
    4344 */
    4445tcb_t * __alloc_tls(void **data, size_t size)
    4546{
    46         tcb_t *result;
     47        tcb_t *tcb;
     48       
     49        *data = malloc(sizeof(tcb_t) + size);
    4750
    48         result = malloc(sizeof(tcb_t) + size);
    49         *data = ((void *)result) + sizeof(tcb_t);
    50         return result;
     51        tcb = (tcb_t *) (*data + size);
     52        tcb->self = tcb;
     53
     54        return tcb;
    5155}
    5256
    5357void __free_tls_arch(tcb_t *tcb, size_t size)
    5458{
    55         free(tcb);
     59        void *start = ((void *)tcb) - size;
     60        free(start);
    5661}
    5762
  • uspace/libc/arch/sparc64/src/thread_entry.s

    r002e613 rcfa70add  
    11#
    2 # Copyright (C) 2006 Martin Decky
     2# Copyright (C) 2006 Jakub Jermar
    33# All rights reserved.
    44#
     
    3535#
    3636__thread_entry:
    37 
     37        sethi %hi(_gp), %l7     
     38        call __thread_main              ! %o0 contains address of uarg
     39        or %l7, %lo(_gp), %l7
     40       
     41        ! not reached
     42       
    3843.end __thread_entry
Note: See TracChangeset for help on using the changeset viewer.