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

user mode : entry #3

Open
2 tasks
Martins3 opened this issue Dec 18, 2020 · 5 comments
Open
2 tasks

user mode : entry #3

Martins3 opened this issue Dec 18, 2020 · 5 comments

Comments

@Martins3
Copy link
Owner

Martins3 commented Dec 18, 2020

Context Switch && Interrupt, here I came.

  • dune_config
  • dune_trap_regs : general purpose regs + rip + rflags, we can ignore it savely.
@Martins3
Copy link
Owner Author

Martins3 commented Dec 18, 2020

arch MIPS x86
interrupt ?? ss ip cs ??
context switch ??
  • analyze the ptregs, callee saved register / caller saved register

  • analyze context switch : cpu state other than regular regs

    • cp0
    • cr3
  • mips syscall convention

  • calling convention

@Martins3
Copy link
Owner Author

R0  R1  R2  R3  R4  R5  R6  R7  R8  R9  R10  R11  R12  R13  R14  R15
RAX RCX RDX RBX RSP RBP RSI RDI

ref : https://cs.lmu.edu/~ray/notes/nasmtutorial/

@Martins3
Copy link
Owner Author

Martins3 commented Dec 18, 2020

代码 sysdeps/unix/sysv/linux/x86_64/syscall.S:

/* Usage: long syscall (syscall_number, arg1, arg2, arg3, arg4, arg5, arg6)
   We need to do some arg shifting, the syscall_number will be in
   rax.  */


        .text
ENTRY (syscall)
        movq %rdi, %rax         /* Syscall number -> rax.  */
        movq %rsi, %rdi         /* shift arg1 - arg5.  */
        movq %rdx, %rsi
        movq %rcx, %rdx
        movq %r8, %r10
        movq %r9, %r8
        movq 8(%rsp),%r9        /* arg6 is on the stack.  */
        syscall                 /* Do the system call.  */
        cmpq $-4095, %rax       /* Check %rax for error.  */
        jae SYSCALL_ERROR_LABEL /* Jump to error handler if error.  */
L(pseudo_end):
        ret                     /* Return to caller.  */

@Martins3
Copy link
Owner Author

GPR parameter
%rdi 1st
%rsi 2st
%rdx 3st
%rcx 4st
%r8 5st
%r9 5st

@Martins3
Copy link
Owner Author

Martins3 commented Dec 19, 2020

	ret = __dune_enter(dune_fd, conf); // %rdi -> dune_fd     %rsi->dune_conf
.globl __dune_enter
__dune_enter:
	pushfq
	subq	$REG_END, %rsp
	SAVE_REGS 1, 0
	SAVE_REST
	movq	%rsp, DUNE_CFG_RSP(%rsi) /* move %rsp to dune_conf::rsp */
	movq	%rsi, %rdx                                / *  dune_conf : rdx, parameter 4 */
	movq	$IOCTL_DUNE_ENTER, %rsi /* paramter 3 */
	movq	$16, %rax /* __NR_ioctl */       /* paramter 1, and dune_fd in %rdi, the paramter 2 */
	syscall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant