2012-04-05 17:00:47 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2013-08-04 14:24:59 -04:00
|
|
|
Copyright(C) Jonas 'Sortie' Termansen 2012, 2014.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
This file is part of the Sortix C Library.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
The Sortix C Library is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
The Sortix C Library is distributed in the hope that it will be useful, but
|
|
|
|
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-07-10 09:26:01 -04:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
|
|
|
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-12-28 15:00:15 -05:00
|
|
|
x64/fork.S
|
2013-07-10 09:26:01 -04:00
|
|
|
Assembly functions related to forking x64 processes.
|
2012-04-05 17:00:47 -04:00
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2013-09-14 12:59:15 -04:00
|
|
|
#define MSRID_FSBASE 0xC0000100
|
|
|
|
#define MSRID_GSBASE 0xC0000101
|
|
|
|
|
2012-04-05 17:00:47 -04:00
|
|
|
.section .text
|
|
|
|
|
2013-08-04 14:24:59 -04:00
|
|
|
.globl __sfork
|
|
|
|
.type __sfork, @function
|
|
|
|
__sfork:
|
2012-04-05 17:00:47 -04:00
|
|
|
pushq %rbp
|
|
|
|
movq %rsp, %rbp
|
|
|
|
|
2013-09-14 12:59:15 -04:00
|
|
|
pushq %rdi
|
2013-08-04 14:24:59 -04:00
|
|
|
pushq %rsi
|
2013-09-14 12:59:15 -04:00
|
|
|
|
2013-08-04 14:24:59 -04:00
|
|
|
movq $.Lafter_fork, (0 * 8)(%rsi) # rip
|
|
|
|
movq $0, (1 * 8)(%rsi) # rax, result is 0 for child
|
|
|
|
movq %rbx, (2 * 8)(%rsi)
|
|
|
|
movq %rcx, (3 * 8)(%rsi)
|
|
|
|
movq %rdx, (4 * 8)(%rsi)
|
|
|
|
movq %rdi, (5 * 8)(%rsi)
|
|
|
|
movq %rsi, (6 * 8)(%rsi)
|
|
|
|
movq %rsp, (7 * 8)(%rsi)
|
|
|
|
movq %rbp, (8 * 8)(%rsi)
|
|
|
|
movq %r8, (9 * 8)(%rsi)
|
|
|
|
movq %r9, (10 * 8)(%rsi)
|
|
|
|
movq %r10, (11 * 8)(%rsi)
|
|
|
|
movq %r11, (12 * 8)(%rsi)
|
|
|
|
movq %r12, (13 * 8)(%rsi)
|
|
|
|
movq %r13, (14 * 8)(%rsi)
|
|
|
|
movq %r14, (15 * 8)(%rsi)
|
|
|
|
movq %r15, (16 * 8)(%rsi)
|
|
|
|
pushfq
|
|
|
|
popq %rax
|
|
|
|
movq %rax, (17 * 8)(%rsi) # rflags
|
2013-09-14 14:05:17 -04:00
|
|
|
movl $MSRID_FSBASE, %edi
|
|
|
|
call rdmsr
|
2013-08-04 14:24:59 -04:00
|
|
|
movq 0(%rsp), %rsi
|
|
|
|
movq %rax, (18 * 8)(%rsi) # fsbase
|
|
|
|
movl $MSRID_GSBASE, %edi
|
|
|
|
call rdmsr
|
|
|
|
movq 0(%rsp), %rsi
|
|
|
|
movq %rax, (19 * 8)(%rsi) # gsbase
|
|
|
|
movq 8(%rsp), %rdi
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2012-08-05 11:35:19 -04:00
|
|
|
call tfork
|
2012-04-05 17:00:47 -04:00
|
|
|
|
2013-12-29 16:51:52 -05:00
|
|
|
.Lafter_fork:
|
2012-04-05 17:00:47 -04:00
|
|
|
# The value in %rax determines whether we are child or parent. There is no
|
|
|
|
# need to clean up the stack from the above pushes, leaveq sets %rsp to %rbp
|
|
|
|
# which does that for us.
|
|
|
|
leaveq
|
|
|
|
retq
|
2013-08-04 14:24:59 -04:00
|
|
|
.size __sfork, . - __sfork
|