Ignore:
Timestamp:
Jun 21, 2017, 8:35:30 AM (5 years ago)
Author:
max@…
Message:

Update. The kernel now enables the GDT/IDT, and has trap entries. A
x86_printf function is added for debugging purposes only. The new Makefile
will come in another commit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/hal/x86_64/hal_kentry.S

    r25 r29  
    11/*
    2  * hal_kentry.S - exception/interrupt/syscall kernel entry point for MIPS32
     2 * hal_kentry.S - Entry points into the kernel (traps, interrupts, syscalls)
    33 *
    4  * AUthors   Ghassan Almaless (2007,2008,2009,2010,2011,2012)
    5  *           Mohamed Lamine Karaoui (2015)
    6  *           Alain Greiner (2017)
    7  *
    8  * Copyright (c) UPMC Sorbonne Universites
     4 * Copyright (c) 2017 Maxime Villard
    95 *
    106 * This file is part of ALMOS-MKH.
     
    2016 *
    2117 * You should have received a copy of the GNU General Public License
    22  * along with ALMOS-MKH; if not, write to the Free Software Foundation,
     18 * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
    2319 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
    2420 */
    2521
     22#define x86_ASM
     23#include <hal_boot.h>
     24#include <hal_kentry.h>
    2625
    27 #---------------------------------------------------------------------------------
    28 # This code is the unique kernel entry point in case of exception, interrupt,
    29 # or syscall for the TSAR_MIPS32 architecture. 
    30 #
    31 # - If the core is in user mode:
    32 #   . we desactivate the MMU.
    33 #   . we save the context in the uzone of the calling thread descriptor.
    34 #   . we increment the cores_in_kernel variable.
    35 #   . we call the relevant exception/interrupt/syscall handler
    36 #
    37 # - If the core is already in kernel mode:
    38 #   . we save the context in the kernel stack
    39 #   . we call the relevant exception/interrupt/syscall handler
    40 #
    41 # - In both cases, when the handler returns:
    42 #   . we restore the context
    43 #   . we reactivate the MMU ???
    44 #---------------------------------------------------------------------------------
     26#define TRAPENTRY(a)    \
     27        pushq $(a);     \
     28        jmp alltraps;
    4529
    46         .section   .kentry,"ax",@progbits
    47         .extern    cpu_do_interrupt
    48         .extern    cpu_do_exception
    49         .extern    cpu_do_syscall
    50         .extern    cpu_kentry
    51         .extern    cpu_kexit
     30#define ZTRAPENTRY(a) \
     31        pushq $0; \
     32        TRAPENTRY(a)
    5233
    53         .global    kentry
    54         .global    kentry_load
     34        .text
     35        .globl  hal_trap_entry
     36        .type   hal_trap_entry, @function
    5537
    56 #define SAVE_SIZE      CPU_REGS_NR*4
    57 #define LID_WIDTH      2
    58 #define CXY_WIDTH      8
    59 #define CXY_MASK       0xFF
    60 #define MMU_MODE_MASK  0xF
    61 #define GID_MASK       0x3FF   
    62 #define LID_MASK       0x3     
     38ASM_ENTRY(x86_trap00)
     39        ZTRAPENTRY(T_DIVIDE)
    6340
    64 #---------------------------------------------------------------------------------
    65 # Kernel Entry point
    66 #---------------------------------------------------------------------------------
     41ASM_ENTRY(x86_trap01)
     42        ZTRAPENTRY(T_TRCTRAP)
    6743
    68 kentry:
    69        
    70 #---------------------------------------------------------------------------------------       
    71 # this code is executed when the core is in user mode:
    72 # - we use the uzone defined in user thread descriptor.
    73 # - we set the MMU off, and save the CP2_MODE register to uzone.
    74 # - we save the user thread stack pointer to uzone and load the kernel stack pointer
    75 # - we store the uzone pointer in $27
     44ASM_ENTRY(x86_trap02)
     45        ZTRAPENTRY(T_NMI)
    7646
    77 user_mode:
     47ASM_ENTRY(x86_trap03)
     48        ZTRAPENTRY(T_BPTFLT)
    7849
    79 #---------------------------------------------------------------------------------------       
    80 # this code is executed when the core is in kernel mode:
    81 # - we use an uzone allocated in kernel stack.
    82 # - we set the MMU off, set the MMU data_paddr extension to local_cxy,
    83 #   and save the CP2_MODE and CP2_DEXT to uzone.
    84 # - we save the kernel stack pointer to uzone and load the new kernel stack pointer
    85 # - we store the uzone pointer in $27
     50ASM_ENTRY(x86_trap04)
     51        ZTRAPENTRY(T_OFLOW)
    8652
    87 kernel_mode:
     53ASM_ENTRY(x86_trap05)
     54        ZTRAPENTRY(T_BOUND)
    8855
    89 #--------------------------------------------------------------------------------------
    90 # this code is executed in both modes, with the two following assumptions:
    91 # - $27 contains the pointer on uzone to save the cpu registers
    92 # - $29 contains the kernel stack pointer
     56ASM_ENTRY(x86_trap06)
     57        ZTRAPENTRY(T_PRIVINFLT)
    9358
    94 unified_mode:   
     59ASM_ENTRY(x86_trap07)
     60        ZTRAPENTRY(T_DNA)
    9561
    96 #---------------------------------------------------------------------------------------
    97 # Depending on XCODE (in $1) , call the apropriate handler. The three called
    98 # functions take the same two arguments: thread pointer and uzone pointer.
     62ASM_ENTRY(x86_trap08)
     63        TRAPENTRY(T_DOUBLEFLT)
    9964
     65ASM_ENTRY(x86_trap09)
     66        ZTRAPENTRY(T_FPOPFLT)
    10067
    101 cause_excp:
     68ASM_ENTRY(x86_trap0a)
     69        TRAPENTRY(T_TSSFLT)
    10270
    103 cause_sys:
     71ASM_ENTRY(x86_trap0b)
     72        ZTRAPENTRY(T_SEGNPFLT)
    10473
    105 cause_int:
     74ASM_ENTRY(x86_trap0c)
     75        ZTRAPENTRY(T_STKFLT)
    10676
    107 # -----------------------------------------------------------------------------------
    108 # Kentry exit
    109 # -----------------------------------------------------------------------------------
    110 kentry_exit:
     77ASM_ENTRY(x86_trap0d)
     78        ZTRAPENTRY(T_PROTFLT)
    11179
    112 # Possible value for MMU_MODE
    113 # In kernel mode : 0x7/0x3
    114 # In user mode   : 0xF
     80ASM_ENTRY(x86_trap0e)
     81        TRAPENTRY(T_PAGEFLT)
    11582
    116 # DP_EXT can either be local or remote
    117 # Once these register set we can no longuer
    118 # access global data
     83ASM_ENTRY(x86_trap0f)
     84        ZTRAPENTRY(T_ASTFLT)
    11985
    120 out_mmu_F:
     86ASM_ENTRY(x86_trap10)
     87        ZTRAPENTRY(T_ARITHTRAP)
    12188
    122 out_mmu_7:
     89ASM_ENTRY(x86_trap11)
     90        TRAPENTRY(T_ALIGNFLT)
    12391
    124 out_mmu_3:
     92ASM_ENTRY(x86_trap12)
     93        ZTRAPENTRY(T_MCA)
    12594
    126 out_kentry:
     95ASM_ENTRY(x86_trap13)
     96        ZTRAPENTRY(T_XMM)
    12797
    128 kentry_load:
    129         # theses nops are required to load the eret instruction
    130         # while we are in virtual mode (processor pipeline) ?
     98ASM_ENTRY(x86_trap14)
     99ASM_ENTRY(x86_trap15)
     100ASM_ENTRY(x86_trap16)
     101ASM_ENTRY(x86_trap17)
     102ASM_ENTRY(x86_trap18)
     103ASM_ENTRY(x86_trap19)
     104ASM_ENTRY(x86_trap1a)
     105ASM_ENTRY(x86_trap1b)
     106ASM_ENTRY(x86_trap1c)
     107ASM_ENTRY(x86_trap1d)
     108ASM_ENTRY(x86_trap1e)
     109ASM_ENTRY(x86_trap1f)
     110        /* 20 - 31 reserved for future exp */
     111        ZTRAPENTRY(T_RESERVED)
    131112
     113/*
     114 * Arguments pushed on the stack:
     115 *  tf_trapno
     116 *  tf_err: Dummy inserted if not defined
     117 *  tf_rip
     118 *  tf_cs
     119 *  tf_rflags
     120 *  tf_rsp
     121 *  tf_ss
     122 */
     123alltraps:
     124        movq    %rsp,%rdi
     125        call    hal_trap_entry
     126        /* NOTREACHED */
    132127
    133 #-------------------------------------------------------------------------------
     128        .data
     129        .globl  x86_traps
     130        .type   x86_traps, @object
    134131
     132        .align  64
     133x86_traps:
     134        .quad   x86_trap00, x86_trap01
     135        .quad   x86_trap02, x86_trap03
     136        .quad   x86_trap04, x86_trap05
     137        .quad   x86_trap06, x86_trap07
     138        .quad   x86_trap08, x86_trap09
     139        .quad   x86_trap0a, x86_trap0b
     140        .quad   x86_trap0c, x86_trap0d
     141        .quad   x86_trap0e, x86_trap0f
     142        .quad   x86_trap10, x86_trap11
     143        .quad   x86_trap12, x86_trap13
     144        .quad   x86_trap14, x86_trap15
     145        .quad   x86_trap16, x86_trap17
     146        .quad   x86_trap18, x86_trap19
     147        .quad   x86_trap1a, x86_trap1b
     148        .quad   x86_trap1c, x86_trap1d
     149        .quad   x86_trap1e, x86_trap1f
     150
Note: See TracChangeset for help on using the changeset viewer.