Changeset a1f60f3 in mainline for kernel/arch/amd64/src/asm_utils.S


Ignore:
Timestamp:
2010-06-27T23:04:20Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
64f6ef04
Parents:
33dac7d
Message:

move from "kernel" memory model to "large" memory model
get rid of the extra identity mapping of the physical memory at -2 GB

File:
1 edited

Legend:

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

    r33dac7d ra1f60f3  
    2727#
    2828
    29 #define IREGISTER_SPACE 80
    30 
    31 #define IOFFSET_RAX     0x0
    32 #define IOFFSET_RCX     0x8
    33 #define IOFFSET_RDX     0x10
    34 #define IOFFSET_RSI     0x18
    35 #define IOFFSET_RDI     0x20
    36 #define IOFFSET_R8      0x28
    37 #define IOFFSET_R9      0x30
    38 #define IOFFSET_R10     0x38
    39 #define IOFFSET_R11     0x40
    40 #define IOFFSET_RBP     0x48
    41 
    42 #  Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int has no error word
    43 # and 1 means interrupt with error word
    44 #define ERROR_WORD_INTERRUPT_LIST 0x00027D00
     29#define IREGISTER_SPACE  80
     30
     31#define IOFFSET_RAX  0x00
     32#define IOFFSET_RCX  0x08
     33#define IOFFSET_RDX  0x10
     34#define IOFFSET_RSI  0x18
     35#define IOFFSET_RDI  0x20
     36#define IOFFSET_R8   0x28
     37#define IOFFSET_R9   0x30
     38#define IOFFSET_R10  0x38
     39#define IOFFSET_R11  0x40
     40#define IOFFSET_RBP  0x48
     41
     42# Mask for interrupts 0 - 31 (bits 0 - 31) where 0 means that int
     43# has no error word  and 1 means interrupt with error word
     44
     45#define ERROR_WORD_INTERRUPT_LIST  0x00027D00
    4546
    4647#include <arch/pm.h>
    4748#include <arch/mm/page.h>
    48        
     49
    4950.text
    5051.global interrupt_handlers
     
    5354
    5455panic_printf:
    55         movq $halt, (%rsp)
     56        movabsq $halt, %rax
     57        movq %rax, (%rsp)
    5658        jmp printf
    5759
     
    7678        jmp _memsetw
    7779
    78 #define MEMCPY_DST      %rdi
    79 #define MEMCPY_SRC      %rsi
    80 #define MEMCPY_SIZE     %rdx
     80#define MEMCPY_DST   %rdi
     81#define MEMCPY_SRC   %rsi
     82#define MEMCPY_SIZE  %rdx
    8183
    8284/**
     
    8991 * or copy_to_uspace().
    9092 *
    91  * @param MEMCPY_DST    Destination address.
    92  * @param MEMCPY_SRC    Source address.
    93  * @param MEMCPY_SIZE   Number of bytes to copy.
     93 * @param MEMCPY_DST  Destination address.
     94 * @param MEMCPY_SRC  Source address.
     95 * @param MEMCPY_SIZE Number of bytes to copy.
    9496 *
    9597 * @retrun MEMCPY_DST on success, 0 on failure.
     98 *
    9699 */
    97100memcpy:
     
    99102memcpy_to_uspace:
    100103        movq MEMCPY_DST, %rax
    101 
     104       
    102105        movq MEMCPY_SIZE, %rcx
    103         shrq $3, %rcx                   /* size / 8 */
    104        
    105         rep movsq                       /* copy as much as possible word by word */
    106 
     106        shrq $3, %rcx           /* size / 8 */
     107       
     108        rep movsq               /* copy as much as possible word by word */
     109       
    107110        movq MEMCPY_SIZE, %rcx
    108         andq $7, %rcx                   /* size % 8 */
     111        andq $7, %rcx           /* size % 8 */
    109112        jz 0f
    110113       
    111         rep movsb                       /* copy the rest byte by byte */
    112        
    113 0:
    114         ret                             /* return MEMCPY_SRC, success */
     114        rep movsb               /* copy the rest byte by byte */
     115       
     116        0:
     117                ret                 /* return MEMCPY_SRC, success */
    115118
    116119memcpy_from_uspace_failover_address:
    117120memcpy_to_uspace_failover_address:
    118         xorq %rax, %rax                 /* return 0, failure */
     121        xorq %rax, %rax         /* return 0, failure */
    119122        ret
    120123
     
    124127#
    125128has_cpuid:
    126         pushfq                  # store flags
    127         popq %rax               # read flags
    128         movq %rax,%rdx          # copy flags
    129         btcl $21,%edx           # swap the ID bit
     129        pushfq                 # store flags
     130        popq %rax              # read flags
     131        movq %rax, %rdx        # copy flags
     132        btcl $21, %edx         # swap the ID bit
    130133        pushq %rdx
    131         popfq                   # propagate the change into flags
     134        popfq                  # propagate the change into flags
    132135        pushfq
    133         popq %rdx               # read flags   
    134         andl $(1<<21),%eax      # interested only in ID bit
    135         andl $(1<<21),%edx
    136         xorl %edx,%eax          # 0 if not supported, 1 if supported
     136        popq %rdx              # read flags
     137        andl $(1 << 21), %eax  # interested only in ID bit
     138        andl $(1 << 21), %edx
     139        xorl %edx, %eax        # 0 if not supported, 1 if supported
    137140        ret
    138141
    139142cpuid:
    140         movq %rbx, %r10  # we have to preserve rbx across function calls
    141 
    142         movl %edi,%eax  # load the command into %eax
    143 
    144         cpuid   
    145         movl %eax,0(%rsi)
    146         movl %ebx,4(%rsi)
    147         movl %ecx,8(%rsi)
    148         movl %edx,12(%rsi)
    149 
     143        movq %rbx, %r10        # we have to preserve rbx across function calls
     144       
     145        movl %edi,%eax         # load the command into %eax
     146       
     147        cpuid
     148        movl %eax, 0(%rsi)
     149        movl %ebx, 4(%rsi)
     150        movl %ecx, 8(%rsi)
     151        movl %edx, 12(%rsi)
     152       
    150153        movq %r10, %rbx
    151154        ret
     
    157160        wrmsr
    158161        ret
    159        
     162
    160163read_efer_flag:
    161164        movq $0xc0000080, %rcx
    162165        rdmsr
    163         ret             
     166        ret
    164167
    165168# Push all volatile general purpose registers on stack
     
    190193.endm
    191194
    192 #define INTERRUPT_ALIGN 128
    193        
     195#define INTERRUPT_ALIGN  128
     196
    194197## Declare interrupt handlers
    195198#
     
    200203#
    201204.macro handler i n
    202 
     205       
    203206        /*
    204207         * Choose between version with error code and version without error
     
    209212         * Therefore we align the interrupt handlers.
    210213         */
    211 
     214       
    212215        .iflt \i-32
    213216                .if (1 << \i) & ERROR_WORD_INTERRUPT_LIST
     
    220223                         * Version without error word,
    221224                         */
    222                         subq $(IREGISTER_SPACE+8), %rsp
     225                        subq $(IREGISTER_SPACE + 8), %rsp
    223226                .endif
    224227        .else
     
    226229                 * Version without error word,
    227230                 */
    228                 subq $(IREGISTER_SPACE+8), %rsp
    229         .endif 
    230 
     231                subq $(IREGISTER_SPACE + 8), %rsp
     232        .endif
     233       
    231234        save_all_gpr
    232235        cld
    233 
     236       
    234237        # Stop stack traces here
    235238        xorq %rbp, %rbp
    236 
    237         movq $(\i), %rdi        # %rdi - first parameter
    238         movq %rsp, %rsi         # %rsi - pointer to istate
    239         call exc_dispatch       # exc_dispatch(i, istate)
     239       
     240        movq $(\i), %rdi    # %rdi - first parameter
     241        movq %rsp, %rsi     # %rsi - pointer to istate
     242        call exc_dispatch   # exc_dispatch(i, istate)
    240243       
    241244        restore_all_gpr
    242245        # $8 = Skip error word
    243         addq $(IREGISTER_SPACE+8), %rsp
     246        addq $(IREGISTER_SPACE + 8), %rsp
    244247        iretq
    245 
     248       
    246249        .align INTERRUPT_ALIGN
    247         .if (\n-\i)-1
    248         handler "(\i+1)",\n
     250        .if (\n - \i) - 1
     251                handler "(\i + 1)", \n
    249252        .endif
    250253.endm
     
    252255.align INTERRUPT_ALIGN
    253256interrupt_handlers:
    254 h_start:
    255         handler 0 IDT_ITEMS
    256 h_end:
     257        h_start:
     258                handler 0 IDT_ITEMS
     259        h_end:
    257260
    258261## Low-level syscall handler
    259 # 
     262#
    260263# Registers on entry:
    261264#
    262 # @param rcx            Userspace return address.
    263 # @param r11            Userspace RLFAGS.
    264 #
    265 # @param rax            Syscall number.
    266 # @param rdi            1st syscall argument.
    267 # @param rsi            2nd syscall argument.
    268 # @param rdx            3rd syscall argument.
    269 # @param r10            4th syscall argument. Used instead of RCX because the
    270 #                       SYSCALL instruction clobbers it.
    271 # @param r8             5th syscall argument.
    272 # @param r9             6th syscall argument.
    273 #
    274 # @return               Return value is in rax.
     265# @param rcx Userspace return address.
     266# @param r11 Userspace RLFAGS.
     267#
     268# @param rax Syscall number.
     269# @param rdi 1st syscall argument.
     270# @param rsi 2nd syscall argument.
     271# @param rdx 3rd syscall argument.
     272# @param r10 4th syscall argument. Used instead of RCX because
     273#            the SYSCALL instruction clobbers it.
     274# @param r8  5th syscall argument.
     275# @param r9  6th syscall argument.
     276#
     277# @return Return value is in rax.
    275278#
    276279syscall_entry:
    277         swapgs                  # Switch to hidden gs   
    278         #
    279         # %gs:0                 Scratch space for this thread's user RSP
    280         # %gs:8                 Address to be used as this thread's kernel RSP
     280        swapgs            # Switch to hidden gs
    281281        #
    282         movq %rsp, %gs:0        # Save this thread's user RSP
    283         movq %gs:8, %rsp        # Set this thread's kernel RSP
    284         swapgs                  # Switch back to remain consistent
     282        # %gs:0 Scratch space for this thread's user RSP
     283        # %gs:8 Address to be used as this thread's kernel RSP
     284        #
     285        movq %rsp, %gs:0  # Save this thread's user RSP
     286        movq %gs:8, %rsp  # Set this thread's kernel RSP
     287        swapgs            # Switch back to remain consistent
    285288        sti
    286289       
    287290        pushq %rcx
    288291        pushq %r11
    289 
    290         movq %r10, %rcx         # Copy the 4th argument where it is expected
     292       
     293        movq %r10, %rcx   # Copy the 4th argument where it is expected
    291294        pushq %rax
    292295        call syscall_handler
    293296        addq $8, %rsp
    294                
     297       
    295298        popq %r11
    296299        popq %rcx
    297 
     300       
    298301        cli
    299302        swapgs
    300         movq %gs:0, %rsp        # Restore the user RSP
     303        movq %gs:0, %rsp  # Restore the user RSP
    301304        swapgs
    302 
     305       
    303306        sysretq
    304307
     
    306309.global interrupt_handler_size
    307310
    308 interrupt_handler_size: .quad (h_end-h_start)/IDT_ITEMS
     311interrupt_handler_size: .quad (h_end - h_start) / IDT_ITEMS
Note: See TracChangeset for help on using the changeset viewer.