Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/amd64/src/asm.S

    r4236b18 re98f1c3e  
    2727 */
    2828
     29#include <abi/asmtool.h>
    2930#include <arch/pm.h>
    3031#include <arch/mm/page.h>
    3132#include <arch/istate_struct.h>
     33#include <arch/kseg_struct.h>
     34#include <arch/cpu.h>
     35#include <arch/smp/apic.h>
    3236
    3337.text
    34 .global interrupt_handlers
    35 .global syscall_entry
    36 .global cpuid
    37 .global has_cpuid
    38 .global read_efer_flag
    39 .global set_efer_flag
    40 .global memcpy_from_uspace
    41 .global memcpy_to_uspace
    42 .global memcpy_from_uspace_failover_address
    43 .global memcpy_to_uspace_failover_address
    44 .global early_putchar
    4538
    4639#define MEMCPY_DST   %rdi
     
    6457 *
    6558 */
    66 memcpy_from_uspace:
    67 memcpy_to_uspace:
     59FUNCTION_BEGIN(memcpy_from_uspace)
     60FUNCTION_BEGIN(memcpy_to_uspace)
    6861        movq MEMCPY_DST, %rax
    6962       
     
    8174        0:
    8275                ret                 /* return MEMCPY_SRC, success */
    83 
    84 memcpy_from_uspace_failover_address:
    85 memcpy_to_uspace_failover_address:
     76FUNCTION_END(memcpy_from_uspace)
     77FUNCTION_END(memcpy_to_uspace)
     78
     79SYMBOL(memcpy_from_uspace_failover_address)
     80SYMBOL(memcpy_to_uspace_failover_address)
    8681        xorl %eax, %eax         /* return 0, failure */
    8782        ret
     
    9287*
    9388*/
    94 has_cpuid:
     89FUNCTION_BEGIN(has_cpuid)
    9590        /* Load RFLAGS */
    9691        pushfq
     
    9994       
    10095        /* Flip the ID bit */
    101         btcl $21, %edx
     96        xorl $RFLAGS_ID, %edx
    10297       
    10398        /* Store RFLAGS */
     
    108103        /* Get the ID bit again */
    109104        popq %rdx
    110         andl $(1 << 21), %eax
    111         andl $(1 << 21), %edx
     105        andl $RFLAGS_ID, %eax
     106        andl $RFLAGS_ID, %edx
    112107       
    113108        /* 0 if not supported, 1 if supported */
    114109        xorl %edx, %eax
    115110        ret
    116 
    117 cpuid:
     111FUNCTION_END(has_cpuid)
     112
     113FUNCTION_BEGIN(cpuid)
    118114        /* Preserve %rbx across function calls */
    119115        movq %rbx, %r10
     
    130126        movq %r10, %rbx
    131127        ret
    132 
    133 set_efer_flag:
    134         movl $0xc0000080, %ecx
     128FUNCTION_END(cpuid)
     129
     130/** Enable local APIC
     131 *
     132 * Enable local APIC in MSR.
     133 *
     134 */
     135FUNCTION_BEGIN(enable_l_apic_in_msr)
     136        movl $AMD_MSR_APIC_BASE, %ecx
    135137        rdmsr
    136         btsl %edi, %eax
     138        orl $(L_APIC_BASE | AMD_APIC_BASE_GE), %eax
    137139        wrmsr
    138140        ret
    139 
    140 read_efer_flag:
    141         movl $0xc0000080, %ecx
    142         rdmsr
    143         ret
     141FUNCTION_END(enable_l_apic_in_msr)
    144142
    145143/*
     
    157155
    158156.macro handler i
    159 .global int_\i
    160 int_\i:
     157SYMBOL(int_\i)
    161158
    162159        /*
     
    204201
    205202        /*
     203         * Is this trap from the kernel?
     204         */
     205        cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)
     206        jz 0f
     207
     208        /*
     209         * Switch to kernel FS base.
     210         */
     211        swapgs
     212        movl $AMD_MSR_FS, %ecx
     213        movl %gs:KSEG_OFFSET_FSBASE, %eax
     214        movl %gs:KSEG_OFFSET_FSBASE+4, %edx
     215        wrmsr
     216        swapgs
     217
     218        /*
    206219         * Imitate a regular stack frame linkage.
    207220         * Stop stack traces here if we came from userspace.
    208221         */
    209         xorl %edx, %edx
    210         cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)
     2220:      movl $0x0, %edx
    211223        cmovnzq %rdx, %rbp
    212224
     
    249261        53,54,55,56,57,58,59,60,61,62,63
    250262
    251 interrupt_handlers:
     263SYMBOL(interrupt_handlers)
    252264.irp cnt, LIST_0_63
    253265        handler \cnt
     
    273285 *
    274286 */
    275 syscall_entry:
     287SYMBOL(syscall_entry)
    276288        /* Switch to hidden %gs */
    277289        swapgs
    278290       
    279         /*
    280          * %gs:0 Scratch space for this thread's user RSP
    281          * %gs:8 Address to be used as this thread's kernel RSP
    282          */
    283        
    284         movq %rsp, %gs:0  /* save this thread's user RSP */
    285         movq %gs:8, %rsp  /* set this thread's kernel RSP */
    286        
     291        movq %rsp, %gs:KSEG_OFFSET_USTACK_RSP  /* save this thread's user RSP */
     292        movq %gs:KSEG_OFFSET_KSTACK_RSP, %rsp  /* set this thread's kernel RSP */
     293
    287294        /*
    288295         * Note that the space needed for the imitated istate structure has been
     
    313320
    314321        /*
     322         * Switch to kernel FS base.
     323         */
     324        movl $AMD_MSR_FS, %ecx
     325        movl %gs:KSEG_OFFSET_FSBASE, %eax
     326        movl %gs:KSEG_OFFSET_FSBASE+4, %edx
     327        wrmsr
     328        movq ISTATE_OFFSET_RDX(%rsp), %rdx      /* restore 3rd argument */
     329
     330        /*
    315331         * Save the return address and the userspace stack on locations that
    316332         * would normally be taken by them.
    317333         */
    318         movq %gs:0, %rax
     334        movq %gs:KSEG_OFFSET_USTACK_RSP, %rax
    319335        movq %rax, ISTATE_OFFSET_RSP(%rsp)
    320336        movq %rcx, ISTATE_OFFSET_RIP(%rsp)
     
    396412 *
    397413 */
    398 early_putchar:
    399        
     414FUNCTION_BEGIN(early_putchar)
    400415#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
    401416       
     
    525540       
    526541        ret
    527 
     542FUNCTION_END(early_putchar)
Note: See TracChangeset for help on using the changeset viewer.