Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch/intel64: various cosmetic improvements after code review #11758

Merged
merged 4 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions arch/x86_64/include/intel64/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,25 +357,25 @@ begin_packed_struct struct ist_s

/* These are defined in intel64_head.S */

extern volatile uint8_t pdpt_low;
extern volatile uint8_t pd_low;
extern volatile uint8_t pt_low;
extern volatile uint8_t g_pdpt_low;
extern volatile uint8_t g_pd_low;
extern volatile uint8_t g_pt_low;

extern volatile uint8_t ist64_low;
extern volatile uint8_t gdt64_low;
extern volatile uint8_t gdt64_ist_low;
extern volatile uint8_t gdt64_low_end;
extern volatile uint8_t g_ist64_low;
extern volatile uint8_t g_gdt64_low;
extern volatile uint8_t g_gdt64_ist_low;
extern volatile uint8_t g_gdt64_low_end;

/* The actual address of the page table and gdt/ist after mapping the kernel
* in high address
*/

extern volatile uint64_t *pdpt;
extern volatile uint64_t *pd;
extern volatile uint64_t *pt;
extern volatile uint64_t *g_pdpt;
extern volatile uint64_t *g_pd;
extern volatile uint64_t *g_pt;

extern volatile struct ist_s *ist64;
extern volatile struct gdt_entry_s *gdt64;
extern volatile struct ist_s *g_ist64;
extern volatile struct gdt_entry_s *g_gdt64;

/****************************************************************************
* Public Function Prototypes
Expand Down
1 change: 1 addition & 0 deletions arch/x86_64/src/intel64/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(SRCS
intel64_schedulesigaction.c
intel64_sigdeliver.c
intel64_usestack.c
intel64_start.c
intel64_handlers.c
intel64_idle.c
intel64_lowsetup.c
Expand Down
3 changes: 2 additions & 1 deletion arch/x86_64/src/intel64/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ CMN_CSRCS += x86_64_allocateheap.c x86_64_copystate.c x86_64_exit.c
CMN_CSRCS += x86_64_getintstack.c x86_64_mdelay.c x86_64_initialize.c
CMN_CSRCS += x86_64_modifyreg8.c x86_64_modifyreg16.c x86_64_modifyreg32.c
CMN_CSRCS += x86_64_nputs.c x86_64_switchcontext.c x86_64_udelay.c

CMN_CSRCS += intel64_createstack.c intel64_initialstate.c intel64_irq.c
CMN_CSRCS += intel64_map_region.c intel64_regdump.c intel64_releasestack.c
CMN_CSRCS += intel64_rtc.c intel64_restore_auxstate.c intel64_savestate.c
Expand All @@ -33,7 +34,7 @@ CMN_CSRCS += intel64_sigdeliver.c intel64_usestack.c x86_64_tcbinfo.c
# Required Intel64 files

CHIP_ASRCS = intel64_saveusercontext.S intel64_fullcontextrestore.S intel64_vectors.S intel64_head.S
CHIP_CSRCS = intel64_handlers.c intel64_idle.c intel64_lowsetup.c
CHIP_CSRCS = intel64_start.c intel64_handlers.c intel64_idle.c intel64_lowsetup.c
CHIP_CSRCS += intel64_serial.c intel64_rng.c intel64_check_capability.c

# Configuration-dependent intel64 files
Expand Down
2 changes: 1 addition & 1 deletion arch/x86_64/src/intel64/intel64.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extern "C"
* Name: intel64_lowsetup
*
* Description:
* Called at the very beginning of _start.
* Called at the very beginning of _nxstart.
* Performs low level initializationincluding setup of the console UART.
* This UART done early so that the serial console is available for
* debugging very early in the boot sequence.
Expand Down
197 changes: 83 additions & 114 deletions arch/x86_64/src/intel64/intel64_fullcontextrestore.S
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,13 @@
#include <arch/irq.h>
#include "x86_64_internal.h"

.file "intel64_fullcontextrestore.S"

/**************************************************************************
* Pre-processor Definitions
**************************************************************************/

/**************************************************************************
* Public Data
**************************************************************************/

/****************************************************************************
* Macros
****************************************************************************/

/* Trace macros, use like trace 'i' to print char to serial port. */

.macro chout, addr, ch
#ifdef CONFIG_DEBUG_FEATURES
mov $\addr, %dx
mov $\ch, %al
out %al, %dx
#endif
.endm

.macro trace, ch
#ifdef CONFIG_DEBUG_FEATURES
push %eax
push %edx
chout 0x3f8, \ch
pop %edx
pop %eax
#endif
.endm
.file "intel64_fullcontextrestore.S"

/**************************************************************************
* Public Functions
**************************************************************************/

.text
.text

/**************************************************************************
* Name: x86_64_fullcontextrestore
Expand All @@ -74,84 +42,85 @@
*
**************************************************************************/

.globl x86_64_fullcontextrestore
.type x86_64_fullcontextrestore, @function
.globl x86_64_fullcontextrestore
.type x86_64_fullcontextrestore, @function
x86_64_fullcontextrestore:
/* The pointer to the register save array in RDI. */

/* Disable interrupts now (the correct RFLAGS will be restored before we
* return
*/

cli

/* Create an interrupt stack frame for the final iret.
*
*
* IRET STACK
* ---------------
* RSP Before ->
* SS
* RSP
* RFLAGS
* CS
* RSP After -> RIP
*
*/

movq (8*REG_SS)(%rdi), %rbx
push %rbx
movq (8*REG_RSP)(%rdi), %rbx
push %rbx

movq (8*REG_RFLAGS)(%rdi), %rbx
push %rbx
movq (8*REG_CS)(%rdi), %rbx
push %rbx
movq (8*REG_RIP)(%rdi), %rbx
push %rbx

/* Save the value of RDI on the stack too */

movq (8*REG_RDI)(%rdi), %rbx
push %rbx

/* Now restore the remaining registers */
movq (8*REG_RSI)(%rdi), %rsi
movq (8*REG_RDX)(%rdi), %rdx
movq (8*REG_RCX)(%rdi), %rcx
movq (8*REG_R8 )(%rdi), %r8
movq (8*REG_R9 )(%rdi), %r9

movq (8*REG_R15)(%rdi), %r15
movq (8*REG_R14)(%rdi), %r14
movq (8*REG_R13)(%rdi), %r13
movq (8*REG_R12)(%rdi), %r12
movq (8*REG_R11)(%rdi), %r11
movq (8*REG_R10)(%rdi), %r10
movq (8*REG_RBP)(%rdi), %rbp
movq (8*REG_RBX)(%rdi), %rbx
movq (8*REG_RAX)(%rdi), %rax

/* Restore the data segment register. I think there is an issue that will
* need to be address here at some time: If the register save area is in
* one data segment and the stack is in another, then the above would not
* work (and, conversely, if they are in the same data segment, the
* following is unnecessary and redundant).
*/

mov (8*REG_DS)(%rdi), %ds
// mov (8*REG_ES)(%rdi), %es // Not used in 64 bit
// mov (8*REG_GS)(%rdi), %gs // Disabled, otherwise we will destroy MSR_GS_BASE
// mov (8*REG_FS)(%rdi), %fs // Disabled, otherwise we will destroy MSR_FS_BASE
// XXX: Should use wrgsbase and wrfsbase to restore the gs and fs register

/* restore xmm registers */
fxrstorq (%rdi)

/* Restore the correct value of EAX and then return */

popq %rdi
iretq
.size x86_64_fullcontextrestore, . - x86_64_fullcontextrestore
.end
/* The pointer to the register save array in RDI. */

/* Disable interrupts now (the correct RFLAGS will be restored before we
* return
*/

cli

/* Create an interrupt stack frame for the final iret.
*
*
* IRET STACK
* ---------------
* RSP Before ->
* SS
* RSP
* RFLAGS
* CS
* RSP After -> RIP
*
*/

movq (8*REG_SS)(%rdi), %rbx
push %rbx
movq (8*REG_RSP)(%rdi), %rbx
push %rbx

movq (8*REG_RFLAGS)(%rdi), %rbx
push %rbx
movq (8*REG_CS)(%rdi), %rbx
push %rbx
movq (8*REG_RIP)(%rdi), %rbx
push %rbx

/* Save the value of RDI on the stack too */

movq (8*REG_RDI)(%rdi), %rbx
push %rbx

/* Now restore the remaining registers */
movq (8*REG_RSI)(%rdi), %rsi
movq (8*REG_RDX)(%rdi), %rdx
movq (8*REG_RCX)(%rdi), %rcx
movq (8*REG_R8 )(%rdi), %r8
movq (8*REG_R9 )(%rdi), %r9

movq (8*REG_R15)(%rdi), %r15
movq (8*REG_R14)(%rdi), %r14
movq (8*REG_R13)(%rdi), %r13
movq (8*REG_R12)(%rdi), %r12
movq (8*REG_R11)(%rdi), %r11
movq (8*REG_R10)(%rdi), %r10
movq (8*REG_RBP)(%rdi), %rbp
movq (8*REG_RBX)(%rdi), %rbx
movq (8*REG_RAX)(%rdi), %rax

/* Restore the data segment register. I think there is an issue that will
* need to be address here at some time: If the register save area is in
* one data segment and the stack is in another, then the above would not
* work (and, conversely, if they are in the same data segment, the
* following is unnecessary and redundant).
*/

mov (8*REG_DS)(%rdi), %ds
/* mov (8*REG_ES)(%rdi), %es // Not used in 64 bit
* mov (8*REG_GS)(%rdi), %gs // Disabled, otherwise we will destroy MSR_GS_BASE
* mov (8*REG_FS)(%rdi), %fs // Disabled, otherwise we will destroy MSR_FS_BASE
* XXX: Should use wrgsbase and wrfsbase to restore the gs and fs register
*/

/* restore xmm registers */
fxrstorq (%rdi)

/* Restore the correct value of EAX and then return */

popq %rdi
iretq
.size x86_64_fullcontextrestore, . - x86_64_fullcontextrestore
.end
Loading
Loading