Ignore:
File:
1 edited

Legend:

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

    re98f1c3e r4236b18  
    2727 */
    2828
    29 #include <abi/asmtool.h>
    3029#include <arch/pm.h>
    3130#include <arch/mm/page.h>
    3231#include <arch/istate_struct.h>
    33 #include <arch/kseg_struct.h>
    34 #include <arch/cpu.h>
    35 #include <arch/smp/apic.h>
    3632
    3733.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
    3845
    3946#define MEMCPY_DST   %rdi
     
    5764 *
    5865 */
    59 FUNCTION_BEGIN(memcpy_from_uspace)
    60 FUNCTION_BEGIN(memcpy_to_uspace)
     66memcpy_from_uspace:
     67memcpy_to_uspace:
    6168        movq MEMCPY_DST, %rax
    6269       
     
    7481        0:
    7582                ret                 /* return MEMCPY_SRC, success */
    76 FUNCTION_END(memcpy_from_uspace)
    77 FUNCTION_END(memcpy_to_uspace)
    78 
    79 SYMBOL(memcpy_from_uspace_failover_address)
    80 SYMBOL(memcpy_to_uspace_failover_address)
     83
     84memcpy_from_uspace_failover_address:
     85memcpy_to_uspace_failover_address:
    8186        xorl %eax, %eax         /* return 0, failure */
    8287        ret
     
    8792*
    8893*/
    89 FUNCTION_BEGIN(has_cpuid)
     94has_cpuid:
    9095        /* Load RFLAGS */
    9196        pushfq
     
    9499       
    95100        /* Flip the ID bit */
    96         xorl $RFLAGS_ID, %edx
     101        btcl $21, %edx
    97102       
    98103        /* Store RFLAGS */
     
    103108        /* Get the ID bit again */
    104109        popq %rdx
    105         andl $RFLAGS_ID, %eax
    106         andl $RFLAGS_ID, %edx
     110        andl $(1 << 21), %eax
     111        andl $(1 << 21), %edx
    107112       
    108113        /* 0 if not supported, 1 if supported */
    109114        xorl %edx, %eax
    110115        ret
    111 FUNCTION_END(has_cpuid)
    112 
    113 FUNCTION_BEGIN(cpuid)
     116
     117cpuid:
    114118        /* Preserve %rbx across function calls */
    115119        movq %rbx, %r10
     
    126130        movq %r10, %rbx
    127131        ret
    128 FUNCTION_END(cpuid)
    129 
    130 /** Enable local APIC
    131  *
    132  * Enable local APIC in MSR.
    133  *
    134  */
    135 FUNCTION_BEGIN(enable_l_apic_in_msr)
    136         movl $AMD_MSR_APIC_BASE, %ecx
     132
     133set_efer_flag:
     134        movl $0xc0000080, %ecx
    137135        rdmsr
    138         orl $(L_APIC_BASE | AMD_APIC_BASE_GE), %eax
     136        btsl %edi, %eax
    139137        wrmsr
    140138        ret
    141 FUNCTION_END(enable_l_apic_in_msr)
     139
     140read_efer_flag:
     141        movl $0xc0000080, %ecx
     142        rdmsr
     143        ret
    142144
    143145/*
     
    155157
    156158.macro handler i
    157 SYMBOL(int_\i)
     159.global int_\i
     160int_\i:
    158161
    159162        /*
     
    201204
    202205        /*
    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         /*
    219206         * Imitate a regular stack frame linkage.
    220207         * Stop stack traces here if we came from userspace.
    221208         */
    222 0:      movl $0x0, %edx
     209        xorl %edx, %edx
     210        cmpq $(GDT_SELECTOR(KTEXT_DES)), ISTATE_OFFSET_CS(%rsp)
    223211        cmovnzq %rdx, %rbp
    224212
     
    261249        53,54,55,56,57,58,59,60,61,62,63
    262250
    263 SYMBOL(interrupt_handlers)
     251interrupt_handlers:
    264252.irp cnt, LIST_0_63
    265253        handler \cnt
     
    285273 *
    286274 */
    287 SYMBOL(syscall_entry)
     275syscall_entry:
    288276        /* Switch to hidden %gs */
    289277        swapgs
    290278       
    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 
     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       
    294287        /*
    295288         * Note that the space needed for the imitated istate structure has been
     
    320313
    321314        /*
    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         /*
    331315         * Save the return address and the userspace stack on locations that
    332316         * would normally be taken by them.
    333317         */
    334         movq %gs:KSEG_OFFSET_USTACK_RSP, %rax
     318        movq %gs:0, %rax
    335319        movq %rax, ISTATE_OFFSET_RSP(%rsp)
    336320        movq %rcx, ISTATE_OFFSET_RIP(%rsp)
     
    412396 *
    413397 */
    414 FUNCTION_BEGIN(early_putchar)
     398early_putchar:
     399       
    415400#if ((defined(CONFIG_EGA)) && (!defined(CONFIG_FB)))
    416401       
     
    540525       
    541526        ret
    542 FUNCTION_END(early_putchar)
     527
Note: See TracChangeset for help on using the changeset viewer.