Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 6d123b3 in mainline


Ignore:
Timestamp:
2012-03-13T15:23:11Z (8 years ago)
Author:
Martin Decky <martin@…>
Branches:
master
Children:
145d16f
Parents:
df366b5e
Message:

respect the o32 ABI when calling C functions from assembler and creating contexts
(thx Adam Hraska)

Files:
3 added
11 edited
6 moved

Legend:

Unmodified
Added
Removed
  • kernel/arch/mips32/include/context.h

    rdf366b5e r6d123b3  
    4242 * Put one item onto the stack to support get_stack_base() and align it up.
    4343 */
    44 #define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
    4545
    4646#ifndef __ASM__
  • kernel/arch/mips32/include/stack.h

    rdf366b5e r6d123b3  
    2727 */
    2828
    29 /** @addtogroup mips32 
     29/** @addtogroup mips32
    3030 * @{
    3131 */
     
    3636#define KERN_mips32_STACK_H_
    3737
    38 #define STACK_ITEM_SIZE         4
    39 #define STACK_ALIGNMENT         8
     38#define STACK_ITEM_SIZE  4
     39#define STACK_ALIGNMENT  8
     40#define ABI_STACK_FRAME  32
    4041
    4142#endif
  • kernel/arch/mips32/src/start.S

    rdf366b5e r6d123b3  
    241241        /* $a1 contains physical address of bootinfo_t */
    242242        jal arch_pre_main
    243         nop
     243        addiu $sp, -ABI_STACK_FRAME
    244244       
    245245        j main_bsp
     
    281281       
    282282        move $a1, $sp
     283        move $a0, $k0
    283284        jal exc_dispatch     /* exc_dispatch(excno, register_space) */
    284         move $a0, $k0
     285        addiu $sp, -ABI_STACK_FRAME
     286        addiu $sp, ABI_STACK_FRAME
    285287       
    286288        REGISTERS_LOAD $sp
     
    323325        sw $t0, ISTATE_OFFSET_T0($sp)  /* save the 5th argument on the stack */
    324326        sw $t1, ISTATE_OFFSET_T1($sp)  /* save the 6th argument on the stack */
     327       
    325328        jal syscall_handler
    326329        sw $v0, ISTATE_OFFSET_V0($sp)  /* save the syscall number on the stack */
     
    357360        move $sp, $k0
    358361       
     362        move $a0, $sp
    359363        jal tlb_refill
    360         move $a0, $sp
     364        addiu $sp, -ABI_STACK_FRAME
     365        addiu $sp, ABI_STACK_FRAME
    361366       
    362367        REGISTERS_LOAD $sp
     
    366371cache_error_handler:
    367372        KERNEL_STACK_TO_K0
    368         sub $k0, ISTATE_SOFT_SIZE 
     373        sub $k0, ISTATE_SOFT_SIZE
    369374        REGISTERS_STORE_AND_EXC_RESET $k0
    370375        sw $sp, ISTATE_OFFSET_SP($k0)
    371376        move $sp, $k0
    372377       
     378        move $a0, $sp
    373379        jal cache_error
    374         move $a0, $sp
     380        addiu $sp, -ABI_STACK_FRAME
     381        addiu $sp, ABI_STACK_FRAME
    375382       
    376383        REGISTERS_LOAD $sp
  • kernel/arch/mips64/include/context.h

    rdf366b5e r6d123b3  
    4242 * Put one item onto the stack to support get_stack_base() and align it up.
    4343 */
    44 #define SP_DELTA  (0 + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
    4545
    4646#ifndef __ASM__
  • kernel/arch/mips64/include/stack.h

    rdf366b5e r6d123b3  
    3838#define STACK_ITEM_SIZE  8
    3939#define STACK_ALIGNMENT  8
     40#define ABI_STACK_FRAME  64
    4041
    4142#endif
  • kernel/arch/mips64/src/start.S

    rdf366b5e r6d123b3  
    241241        /* $a1 contains physical address of bootinfo_t */
    242242        jal arch_pre_main
    243         nop
     243        addiu $sp, -ABI_STACK_FRAME
    244244       
    245245        j main_bsp
     
    281281       
    282282        move $a1, $sp
     283        move $a0, $k0
    283284        jal exc_dispatch     /* exc_dispatch(excno, register_space) */
    284         move $a0, $k0
     285        addiu $sp, -ABI_STACK_FRAME
     286        addiu $sp, ABI_STACK_FRAME
    285287       
    286288        REGISTERS_LOAD $sp
     
    323325        sw $t0, ISTATE_OFFSET_T0($sp)  /* save the 5th argument on the stack */
    324326        sw $t1, ISTATE_OFFSET_T1($sp)  /* save the 6th argument on the stack */
     327       
    325328        jal syscall_handler
    326329        sw $v0, ISTATE_OFFSET_V0($sp)  /* save the syscall number on the stack */
     
    357360        move $sp, $k0
    358361       
     362        move $a0, $sp
    359363        jal tlb_refill
    360         move $a0, $sp
     364        addiu $sp, -ABI_STACK_FRAME
     365        addiu $sp, ABI_STACK_FRAME
    361366       
    362367        REGISTERS_LOAD $sp
     
    366371cache_error_handler:
    367372        KERNEL_STACK_TO_K0
    368         sub $k0, ISTATE_SOFT_SIZE 
     373        sub $k0, ISTATE_SOFT_SIZE
    369374        REGISTERS_STORE_AND_EXC_RESET $k0
    370375        sw $sp, ISTATE_OFFSET_SP($k0)
    371376        move $sp, $k0
    372377       
     378        move $a0, $sp
    373379        jal cache_error
    374         move $a0, $sp
     380        addiu $sp, -ABI_STACK_FRAME
     381        addiu $sp, ABI_STACK_FRAME
    375382       
    376383        REGISTERS_LOAD $sp
  • uspace/lib/c/arch/mips32/Makefile.inc

    rdf366b5e r6d123b3  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips32/include/fibril.h

    rdf366b5e r6d123b3  
    3838
    3939#include <sys/types.h>
     40#include <libarch/stack.h>
     41#include <align.h>
    4042
    41 /* We define our own context_set, because we need to set
    42  * the TLS pointer to the tcb+0x7000
     43#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44
     45/*
     46 * We define our own context_set, because we need to set
     47 * the TLS pointer to the tcb + 0x7000
    4348 *
    4449 * See tls_set in thread.h
    4550 */
    46 #define context_set(c, _pc, stack, size, ptls)                  \
    47         (c)->pc = (sysarg_t) (_pc);                             \
    48         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA;     \
    49         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
    50 
    51 
    52 /* +16 is just for sure that the called function
    53  * have space to store it's arguments
    54  */
    55 #define SP_DELTA        (8+16)
     51#define context_set(c, _pc, stack, size, ptls) \
     52        do { \
     53                (c)->pc = (sysarg_t) (_pc); \
     54                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     55                (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \
     56        } while (0)
    5657
    5758typedef struct  {
  • uspace/lib/c/arch/mips32/src/entry.S

    rdf366b5e r6d123b3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .init, "ax"
     
    4143.ent __entry
    4244__entry:
    43         .frame $sp, 32, $31
    44         .cpload $25
     45        .frame $sp, ABI_STACK_FRAME, $ra
     46        .cpload $t9
    4547       
    46         # FIXME: Reflect exactly ABI specs here
     48        # Allocate the stack frame.
     49        addiu $sp, -ABI_STACK_FRAME
    4750       
    48         addiu $sp, -32
    49         .cprestore 16   # Allow PIC code
     51        # Allow PIC code
     52        .cprestore 16
    5053       
    51         # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
     54        # Pass pcb_ptr to __main() as the first argument. It is already
    5255        # in $a0. As the first argument is passed in $a0, no operation
    5356        # is needed.
     
    5558        jal __main
    5659        nop
    57 .end
     60       
     61        #
     62        # Not reached.
     63        #
     64        addiu $sp, ABI_STACK_FRAME
     65.end __entry
  • uspace/lib/c/arch/mips32/src/entryjmp.S

    rdf366b5e r6d123b3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .text
     
    4143entry_point_jmp:
    4244        # tmp := entry_point
    43         move $25, $a0
     45        move $t9, $a0
    4446       
    4547        # Pass pcb to the entry point in $a0
    4648        move $a0, $a1
    47         jr $25
    48         nop
    49 .end
     49       
     50        jr $t9
     51        addiu $sp, -ABI_STACK_FRAME
     52        addiu $sp, ABI_STACK_FRAME
     53.end entry_point_jmp
  • uspace/lib/c/arch/mips32/src/thread_entry.S

    rdf366b5e r6d123b3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032
     
    4042.ent __thread_entry
    4143__thread_entry:
    42         .frame $sp, 32, $31
    43         .cpload $25
     44        .frame $sp, ABI_STACK_FRAME, $ra
     45        .cpload $t9
    4446       
    4547        #
    4648        # v0 contains address of uarg.
    4749        #
    48         add $4, $2, 0
     50        add $a0, $v0, 0
    4951       
    50         addiu $sp, -32
     52        # Allocate the stack frame.
     53        addiu $sp, -ABI_STACK_FRAME
     54       
     55        # Allow PIC code
    5156        .cprestore 16
    5257       
     
    5762        # Not reached.
    5863        #
     64        addiu $sp, ABI_STACK_FRAME
    5965.end __thread_entry
  • uspace/lib/c/arch/mips32eb/Makefile.inc

    rdf366b5e r6d123b3  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips64/Makefile.inc

    rdf366b5e r6d123b3  
    2828
    2929ARCH_SOURCES = \
    30         arch/$(UARCH)/src/entry.s \
    31         arch/$(UARCH)/src/entryjmp.s \
    32         arch/$(UARCH)/src/thread_entry.s \
     30        arch/$(UARCH)/src/entry.S \
     31        arch/$(UARCH)/src/entryjmp.S \
     32        arch/$(UARCH)/src/thread_entry.S \
    3333        arch/$(UARCH)/src/syscall.c \
    3434        arch/$(UARCH)/src/fibril.S \
  • uspace/lib/c/arch/mips64/include/fibril.h

    rdf366b5e r6d123b3  
    3838
    3939#include <sys/types.h>
     40#include <libarch/stack.h>
     41#include <align.h>
    4042
    41 /* We define our own context_set, because we need to set
    42  * the TLS pointer to the tcb+0x7000
     43#define SP_DELTA  (ABI_STACK_FRAME + ALIGN_UP(STACK_ITEM_SIZE, STACK_ALIGNMENT))
     44
     45/*
     46 * We define our own context_set, because we need to set
     47 * the TLS pointer to the tcb + 0x7000
    4348 *
    4449 * See tls_set in thread.h
    4550 */
    4651#define context_set(c, _pc, stack, size, ptls) \
    47         (c)->pc = (sysarg_t) (_pc); \
    48         (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
    49         (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t);
    50 
    51 /* +16 is just for sure that the called function
    52  * have space to store it's arguments
    53  */
    54 #define SP_DELTA  (8 + 16)
     52        do { \
     53                (c)->pc = (sysarg_t) (_pc); \
     54                (c)->sp = ((sysarg_t) (stack)) + (size) - SP_DELTA; \
     55                (c)->tls = ((sysarg_t)(ptls)) + 0x7000 + sizeof(tcb_t); \
     56        } while (0)
    5557
    5658typedef struct {
  • uspace/lib/c/arch/mips64/src/entry.S

    rdf366b5e r6d123b3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .init, "ax"
     
    4143.ent __entry
    4244__entry:
    43         .frame $sp, 32, $31
    44         .cpload $25
    45 
    46         # Mips o32 may store its arguments on stack, make space (16 bytes),
    47         # so that it could work with -O0
    48         # Make space additional 16 bytes for the stack frame
    49 
    50         addiu $sp, -32
    51         .cprestore 16   # Allow PIC code
    52 
    53         # Pass pcb_ptr to __main() as the first argument. pcb_ptr is already
     45        .frame $sp, ABI_STACK_FRAME, $ra
     46        .cpload $t9
     47       
     48        # Allocate the stack frame.
     49        addiu $sp, -ABI_STACK_FRAME
     50       
     51        # Allow PIC code
     52        .cprestore 16
     53       
     54        # Pass pcb_ptr to __main() as the first argument. It is already
    5455        # in $a0. As the first argument is passed in $a0, no operation
    5556        # is needed.
    56 
     57       
    5758        jal __main
    5859        nop
    59 .end
     60       
     61        #
     62        # Not reached.
     63        #
     64        addiu $sp, ABI_STACK_FRAME
     65.end __entry
  • uspace/lib/c/arch/mips64/src/entryjmp.S

    rdf366b5e r6d123b3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    3032.section .text
     
    3436## void entry_point_jmp(void *entry_point, void *pcb);
    3537#
    36 # $a0 (=$4)     contains entry_point
    37 # $a1 (=$5)     contains pcb
     38# $a0 (=$4) contains entry_point
     39# $a1 (=$5) contains pcb
    3840#
    3941# Jump to program entry point
     
    4143entry_point_jmp:
    4244        # tmp := entry_point
    43         move $25, $a0
    44 
     45        move $t9, $a0
     46       
    4547        # Pass pcb to the entry point in $a0
    4648        move $a0, $a1
    47         jr $25
    48         nop
    49 .end
     49       
     50        jr $t9
     51        addiu $sp, -ABI_STACK_FRAME
     52        addiu $sp, ABI_STACK_FRAME
     53.end entry_point_jmp
  • uspace/lib/c/arch/mips64/src/thread_entry.S

    rdf366b5e r6d123b3  
    2727#
    2828
     29#include <libarch/stack.h>
     30
    2931.text
    30        
     32
    3133.set noat
    3234.set noreorder
    3335.option pic2
    34        
     36
    3537.globl __thread_entry
    3638
     
    4042.ent __thread_entry
    4143__thread_entry:
    42         .frame $sp, 32, $31
    43         .cpload $25
    44 
     44        .frame $sp, ABI_STACK_FRAME, $ra
     45        .cpload $t9
     46       
    4547        #
    4648        # v0 contains address of uarg.
    4749        #
    48         add $4, $2, 0
    49         # Mips o32 may store its arguments on stack, make space
    50         addiu $sp, -32
     50        add $a0, $v0, 0
     51       
     52        # Allocate the stack frame.
     53        addiu $sp, -ABI_STACK_FRAME
     54       
     55        # Allow PIC code
    5156        .cprestore 16
    5257       
    5358        jal __thread_main
    5459        nop
    55                
     60       
    5661        #
    5762        # Not reached.
    5863        #
     64        addiu $sp, ABI_STACK_FRAME
    5965.end __thread_entry
Note: See TracChangeset for help on using the changeset viewer.