Index: trunk/hal/x86_64/hal_kentry.S
===================================================================
--- trunk/hal/x86_64/hal_kentry.S	(revision 25)
+++ trunk/hal/x86_64/hal_kentry.S	(revision 29)
@@ -1,10 +1,6 @@
 /*
- * hal_kentry.S - exception/interrupt/syscall kernel entry point for MIPS32
+ * hal_kentry.S - Entry points into the kernel (traps, interrupts, syscalls)
  * 
- * AUthors   Ghassan Almaless (2007,2008,2009,2010,2011,2012)
- *           Mohamed Lamine Karaoui (2015)
- *           Alain Greiner (2017)
- *
- * Copyright (c) UPMC Sorbonne Universites
+ * Copyright (c) 2017 Maxime Villard
  * 
  * This file is part of ALMOS-MKH.
@@ -20,115 +16,135 @@
  *
  * You should have received a copy of the GNU General Public License
- * along with ALMOS-MKH; if not, write to the Free Software Foundation,
+ * along with ALMOS-MKH.; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#define x86_ASM
+#include <hal_boot.h>
+#include <hal_kentry.h>
 
-#---------------------------------------------------------------------------------
-# This code is the unique kernel entry point in case of exception, interrupt,
-# or syscall for the TSAR_MIPS32 architecture.  
-#
-# - If the core is in user mode:
-#   . we desactivate the MMU.
-#   . we save the context in the uzone of the calling thread descriptor.
-#   . we increment the cores_in_kernel variable.
-#   . we call the relevant exception/interrupt/syscall handler
-#
-# - If the core is already in kernel mode: 
-#   . we save the context in the kernel stack
-#   . we call the relevant exception/interrupt/syscall handler
-#
-# - In both cases, when the handler returns:
-#   . we restore the context
-#   . we reactivate the MMU ??? 
-#---------------------------------------------------------------------------------
+#define	TRAPENTRY(a)	\
+	pushq $(a);	\
+	jmp alltraps;
 
-	.section   .kentry,"ax",@progbits
-	.extern    cpu_do_interrupt
-	.extern    cpu_do_exception
-	.extern    cpu_do_syscall
-	.extern    cpu_kentry
-	.extern    cpu_kexit
+#define	ZTRAPENTRY(a) \
+	pushq $0; \
+	TRAPENTRY(a)
 
-	.global    kentry
-	.global    kentry_load
+	.text
+	.globl	hal_trap_entry
+	.type	hal_trap_entry, @function
 
-#define SAVE_SIZE      CPU_REGS_NR*4
-#define LID_WIDTH      2
-#define CXY_WIDTH      8
-#define CXY_MASK       0xFF
-#define MMU_MODE_MASK  0xF
-#define GID_MASK       0x3FF	
-#define LID_MASK       0x3	
+ASM_ENTRY(x86_trap00)
+	ZTRAPENTRY(T_DIVIDE)
 
-#---------------------------------------------------------------------------------
-# Kernel Entry point
-#---------------------------------------------------------------------------------
+ASM_ENTRY(x86_trap01)
+	ZTRAPENTRY(T_TRCTRAP)
 
-kentry:
-	
-#---------------------------------------------------------------------------------------	
-# this code is executed when the core is in user mode:
-# - we use the uzone defined in user thread descriptor. 
-# - we set the MMU off, and save the CP2_MODE register to uzone.
-# - we save the user thread stack pointer to uzone and load the kernel stack pointer
-# - we store the uzone pointer in $27
+ASM_ENTRY(x86_trap02)
+	ZTRAPENTRY(T_NMI)
 
-user_mode:
+ASM_ENTRY(x86_trap03)
+	ZTRAPENTRY(T_BPTFLT)
 
-#---------------------------------------------------------------------------------------	
-# this code is executed when the core is in kernel mode:
-# - we use an uzone allocated in kernel stack.
-# - we set the MMU off, set the MMU data_paddr extension to local_cxy,
-#   and save the CP2_MODE and CP2_DEXT to uzone.
-# - we save the kernel stack pointer to uzone and load the new kernel stack pointer
-# - we store the uzone pointer in $27
+ASM_ENTRY(x86_trap04)
+	ZTRAPENTRY(T_OFLOW)
 
-kernel_mode:
+ASM_ENTRY(x86_trap05)
+	ZTRAPENTRY(T_BOUND)
 
-#--------------------------------------------------------------------------------------	
-# this code is executed in both modes, with the two following assumptions:
-# - $27 contains the pointer on uzone to save the cpu registers
-# - $29 contains the kernel stack pointer
+ASM_ENTRY(x86_trap06)
+	ZTRAPENTRY(T_PRIVINFLT)
 
-unified_mode:	
+ASM_ENTRY(x86_trap07)
+	ZTRAPENTRY(T_DNA)
 
-#---------------------------------------------------------------------------------------
-# Depending on XCODE (in $1) , call the apropriate handler. The three called
-# functions take the same two arguments: thread pointer and uzone pointer.
+ASM_ENTRY(x86_trap08)
+	TRAPENTRY(T_DOUBLEFLT)
 
+ASM_ENTRY(x86_trap09)
+	ZTRAPENTRY(T_FPOPFLT)
 
-cause_excp:
+ASM_ENTRY(x86_trap0a)
+	TRAPENTRY(T_TSSFLT)
 
-cause_sys:
+ASM_ENTRY(x86_trap0b)
+	ZTRAPENTRY(T_SEGNPFLT)
 
-cause_int:
+ASM_ENTRY(x86_trap0c)
+	ZTRAPENTRY(T_STKFLT)
 
-# -----------------------------------------------------------------------------------
-# Kentry exit
-# -----------------------------------------------------------------------------------
-kentry_exit:
+ASM_ENTRY(x86_trap0d)
+	ZTRAPENTRY(T_PROTFLT)
 
-# Possible value for MMU_MODE
-# In kernel mode : 0x7/0x3
-# In user mode   : 0xF
+ASM_ENTRY(x86_trap0e)
+	TRAPENTRY(T_PAGEFLT)
 
-# DP_EXT can either be local or remote
-# Once these register set we can no longuer 
-# access global data
+ASM_ENTRY(x86_trap0f)
+	ZTRAPENTRY(T_ASTFLT)
 
-out_mmu_F:
+ASM_ENTRY(x86_trap10)
+	ZTRAPENTRY(T_ARITHTRAP)
 
-out_mmu_7:
+ASM_ENTRY(x86_trap11)
+	TRAPENTRY(T_ALIGNFLT)
 
-out_mmu_3:
+ASM_ENTRY(x86_trap12)
+	ZTRAPENTRY(T_MCA)
 
-out_kentry:
+ASM_ENTRY(x86_trap13)
+	ZTRAPENTRY(T_XMM)
 
-kentry_load:
-	# theses nops are required to load the eret instruction
-	# while we are in virtual mode (processor pipeline) ?
+ASM_ENTRY(x86_trap14)
+ASM_ENTRY(x86_trap15)
+ASM_ENTRY(x86_trap16)
+ASM_ENTRY(x86_trap17)
+ASM_ENTRY(x86_trap18)
+ASM_ENTRY(x86_trap19)
+ASM_ENTRY(x86_trap1a)
+ASM_ENTRY(x86_trap1b)
+ASM_ENTRY(x86_trap1c)
+ASM_ENTRY(x86_trap1d)
+ASM_ENTRY(x86_trap1e)
+ASM_ENTRY(x86_trap1f)
+	/* 20 - 31 reserved for future exp */
+	ZTRAPENTRY(T_RESERVED)
 
+/*
+ * Arguments pushed on the stack:
+ *  tf_trapno
+ *  tf_err: Dummy inserted if not defined
+ *  tf_rip
+ *  tf_cs
+ *  tf_rflags
+ *  tf_rsp
+ *  tf_ss
+ */
+alltraps:
+	movq	%rsp,%rdi
+	call	hal_trap_entry
+	/* NOTREACHED */
 
-#-------------------------------------------------------------------------------
+	.data
+	.globl	x86_traps
+	.type	x86_traps, @object
 
+	.align	64
+x86_traps:
+	.quad	x86_trap00, x86_trap01
+	.quad	x86_trap02, x86_trap03
+	.quad	x86_trap04, x86_trap05
+	.quad	x86_trap06, x86_trap07
+	.quad	x86_trap08, x86_trap09
+	.quad	x86_trap0a, x86_trap0b
+	.quad	x86_trap0c, x86_trap0d
+	.quad	x86_trap0e, x86_trap0f
+	.quad	x86_trap10, x86_trap11
+	.quad	x86_trap12, x86_trap13
+	.quad	x86_trap14, x86_trap15
+	.quad	x86_trap16, x86_trap17
+	.quad	x86_trap18, x86_trap19
+	.quad	x86_trap1a, x86_trap1b
+	.quad	x86_trap1c, x86_trap1d
+	.quad	x86_trap1e, x86_trap1f
+
