1 | /* |
---|
2 | * __cpu-context.S - low-level context operations |
---|
3 | * |
---|
4 | * Copyright (c) 2008,2009,2010,2011,2012 Ghassan Almaless |
---|
5 | * Copyright (c) 2011,2012 UPMC Sorbonne Universites |
---|
6 | * |
---|
7 | * This file is part of ALMOS-kernel. |
---|
8 | * |
---|
9 | * ALMOS-kernel is free software; you can redistribute it and/or modify it |
---|
10 | * under the terms of the GNU General Public License as published by |
---|
11 | * the Free Software Foundation; version 2.0 of the License. |
---|
12 | * |
---|
13 | * ALMOS-kernel is distributed in the hope that it will be useful, but |
---|
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
16 | * General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with ALMOS-kernel; if not, write to the Free Software Foundation, |
---|
20 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
21 | */ |
---|
22 | |
---|
23 | #define KSP 10*4 |
---|
24 | #define TID 9*4 |
---|
25 | #define TSS 8*4 |
---|
26 | #define LOADABLE 7*4 |
---|
27 | #define CR3 6*4 |
---|
28 | #define EIP 5*4 |
---|
29 | #define ESI 4*4 |
---|
30 | #define EDI 3*4 |
---|
31 | #define EBP 2*4 |
---|
32 | #define ESP 1*4 |
---|
33 | #define EBX 0*4 |
---|
34 | |
---|
35 | #define ESP_R0 1*4 |
---|
36 | #define ESP_R1 3*4 |
---|
37 | |
---|
38 | .text |
---|
39 | .global cpu_context_save |
---|
40 | cpu_context_save: |
---|
41 | movl 0(%esp), %edx /* Return Address */ |
---|
42 | movl 4(%esp), %ecx /* ctx pointer */ |
---|
43 | movl %ebx, (EBX)(%ecx) |
---|
44 | movl %esp, (ESP)(%ecx) |
---|
45 | movl %ebp, (EBP)(%ecx) |
---|
46 | movl %edi, (EDI)(%ecx) |
---|
47 | movl %esi, (ESI)(%ecx) |
---|
48 | movl %edx, (EIP)(%ecx) |
---|
49 | /* movl %cr3, (CR3)(%ecx) */ |
---|
50 | movl $0x0, %eax |
---|
51 | ret |
---|
52 | |
---|
53 | .global cpu_context_restore |
---|
54 | .extern cpu_context_load |
---|
55 | cpu_context_restore: |
---|
56 | movl 4(%esp), %ecx /* ctx pointer */ |
---|
57 | movl (LOADABLE)(%ecx), %eax |
---|
58 | test $0x1, %eax |
---|
59 | jz restore |
---|
60 | movl $0x0, (LOADABLE)(%ecx) |
---|
61 | push %ecx |
---|
62 | call cpu_context_load |
---|
63 | restore: |
---|
64 | movl 8(%esp), %eax /* Return Value */ |
---|
65 | movl (TSS)(%ecx), %ebx |
---|
66 | movl (TID)(%ecx), %edx |
---|
67 | movl %edx, (ESP_R1)(%ebx) |
---|
68 | movl (KSP)(%ecx), %edx |
---|
69 | movl %edx, (ESP_R0)(%ebx) |
---|
70 | movl (EBX)(%ecx), %ebx |
---|
71 | movl (ESP)(%ecx), %esp |
---|
72 | movl (EBP)(%ecx), %ebp |
---|
73 | movl (EDI)(%ecx), %edi |
---|
74 | movl (ESI)(%ecx), %esi |
---|
75 | movl (EIP)(%ecx), %edx |
---|
76 | /* movl (CR3)(%ecx), %cr3 */ |
---|
77 | movl %edx, 0(%esp) |
---|
78 | ret |
---|