summaryrefslogtreecommitdiff
path: root/kern/sched_asm.S
blob: d20f129a2248022dc3d068869bd47c975db58d5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/** @file sched_asm.S
 *
 *  @brief scheduling functions.
 *
 *  @author Hanjie Wu (hanjiew)
 *  @bug No functional bugs
 */

#include <x86/seg.h>

.text

.global set_fs
.type set_fs, %function
set_fs:
    mov 0x4(%esp), %fs
    ret

.global set_gs
.type set_gs, %function
set_gs:
    mov 0x4(%esp), %gs
    ret

.macro PERCPU_GETSET name offset
.global get_\name
.type get_\name, %function
get_\name:
    xor %eax, %eax
    mov %fs:\offset(%eax), %eax
    ret

.global set_\name
.type set_\name, %function
set_\name:
    xor %ecx, %ecx
    mov 0x4(%esp), %eax
    mov %eax, %fs:\offset(%ecx)
    ret
.endm

PERCPU_GETSET current 0x0
PERCPU_GETSET idle 0x4
PERCPU_GETSET kthread 0x8
PERCPU_GETSET mapped_phys_page 0xc
PERCPU_GETSET mapped_phys_page_pte 0x10

.global return_to_user
.type return_to_user, %function
return_to_user:
    push %esp
    call check_pending_signals
    add $0x4, %esp
    pop %gs /* restore from stack_frame_t structure */
    pop %fs
    pop %es
    pop %ds
    popa
    iret

.global switch_stack_cleanup
.type switch_stack_cleanup, %function
switch_stack_cleanup:
    mov 0x8(%esp), %eax
    mov 0x4(%esp), %esp
    push %eax
    call cleanup_dead_thread
    add $0x4, %esp
    pop %ebp
    pop %ebx
    pop %esi
    pop %edi
    popf
    ret