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
|
|
|
x86/fork.S
|
2013-07-10 09:26:01 -04:00
|
|
|
Assembly functions related to forking x86 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
|
|
|
pushl %ebp
|
|
|
|
movl %esp, %ebp
|
|
|
|
|
2013-08-04 14:24:59 -04:00
|
|
|
movl 12(%ebp), %ecx
|
|
|
|
push %ecx
|
|
|
|
movl 8(%ebp), %edx
|
|
|
|
push %edx
|
|
|
|
# -- stack is 16-byte aligned -- #
|
|
|
|
|
|
|
|
movl $.Lafter_fork, (0 * 4)(%ecx) # eip
|
|
|
|
movl $0, (1 * 4)(%ecx) # rax, result is 0 for child
|
|
|
|
movl %ebx, (2 * 4)(%ecx)
|
|
|
|
movl %ecx, (3 * 4)(%ecx)
|
|
|
|
movl %edx, (4 * 4)(%ecx)
|
|
|
|
movl %edi, (5 * 4)(%ecx)
|
|
|
|
movl %esi, (6 * 4)(%ecx)
|
|
|
|
movl %esp, (7 * 4)(%ecx)
|
|
|
|
movl %ebp, (8 * 4)(%ecx)
|
|
|
|
pushfl
|
|
|
|
popl %eax
|
|
|
|
movl %eax, (9 * 4)(%ecx) # eflags
|
|
|
|
|
|
|
|
subl $12, %esp
|
2013-09-14 14:05:17 -04:00
|
|
|
pushl $MSRID_FSBASE
|
|
|
|
call rdmsr
|
2013-08-04 14:24:59 -04:00
|
|
|
movl 12(%ebp), %ecx
|
|
|
|
movl %eax, (10 * 4)(%ecx) # fsbase
|
|
|
|
addl $16, %esp
|
|
|
|
|
|
|
|
subl $12, %esp
|
|
|
|
pushl $MSRID_GSBASE
|
|
|
|
call rdmsr
|
|
|
|
movl 12(%ebp), %ecx
|
|
|
|
movl %eax, (11 * 4)(%ecx) # gsbase
|
|
|
|
addl $16, %esp
|
|
|
|
|
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:
|
|
|
|
# The value in %eax: determines whether we are child or parent. There is no
|
2012-04-05 17:00:47 -04:00
|
|
|
# need to clean up the stack from the above pushes, leavel sets %esp to %ebp
|
|
|
|
# which does that for us.
|
|
|
|
leavel
|
|
|
|
retl
|
2013-08-04 14:24:59 -04:00
|
|
|
.size __sfork, . - __sfork
|