Removed excessive traces in loadelf.c
[marionette.git] / kernel / thread-asm.S
blobce98d39ca16f6f7b62665c93644082e2430f6321
1 /*
2  *    Copyright (c) 2008 Joshua Phillips. All rights reserved.
3  *  
4  *  Redistribution and use in source and binary forms, with or without
5  *  modification, are permitted provided that the following conditions are
6  *  met:
7  *  
8  *    1. Redistributions of source code must retain the above copyright
9  *       notice, this list of conditions and the following disclaimer.
10  *    2. Redistributions in binary form must reproduce the above copyright
11  *       notice, this list of conditions and the following disclaimer in
12  *       the documentation and/or other materials provided with the
13  *       distribution.
14  *  
15  *  THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
16  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  *  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  *  DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
19  *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
21  *  GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
23  *  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24  *  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
25  *  IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
28 .global context_switch
29 context_switch:
30     /* (struct pusha_struct *regs, uint32_t eip, uint32_t eflags */
31     movl 4(%esp),%eax
32     movl 8(%esp),%ecx
33     movl 12(%esp),%edx
34     movl 12(%eax),%esp
35     pushl %edx     /* eflags */
36     pushl $0x08    /* cs (SEG_DPL0_CODE) */
37     pushl %ecx     /* eip */
38     pushl 28(%eax) /* eax */
39     pushl 24(%eax) /* ecx */
40     pushl 20(%eax) /* edx */
41     pushl 16(%eax) /* ebx */
42     pushl 12(%eax) /* esp */
43     pushl 8(%eax)  /* ebp */
44     pushl 4(%eax)  /* esi */
45     pushl (%eax)   /* edi */
46     popa
47     iret
49 .global context_switch_user
50 context_switch_user:
51     /* (struct pusha_struct *regs, uint32_t eip, uint32_t eflags */
52     movl 4(%esp),%eax
53     movl 8(%esp),%ecx
54     movl 12(%esp),%edx
55     movl $0x23,%ebx /* ds (SEG_DPL3_DATA) */
56     movw %bx,%ds
57     movw %bx,%es
58     movw %bx,%fs
59     movw %bx,%gs
60     pushl $0x23     /* ss (SEG_DPL3_DATA) */
61     pushl 12(%eax)  /* esp */
62     pushl %edx      /* eflags */
63     pushl $0x1B     /* cs (SEG_DPL3_CODE) */
64     pushl %ecx      /* eip */
65     pushl 28(%eax)  /* eax */
66     pushl 24(%eax)  /* ecx */
67     pushl 20(%eax)  /* edx */
68     pushl 16(%eax)  /* ebx */
69     pushl 12(%eax)  /* esp */
70     pushl 8(%eax)   /* ebp */
71     pushl 4(%eax)   /* esi */
72     pushl (%eax)    /* edi */
73     popa
74     iret
76 .global store_call
77 store_call:
78     leal 8(%esp),%eax /* get original stack pointer */
79     pushf             /* store flags */
80     pushl -4(%eax)    /* store return address */
81     pushl %edi
82     pushl %esi
83     pushl %ebp
84     pushl %eax
85     pushl %ebx
86     call thread_save_call_state
87     addl $28,%esp
88     call *4(%esp)
89     ret