summaryrefslogtreecommitdiffhomepage
path: root/dev/ZKA/HALKit/AMD64/HalSMPCoreManager.asm
blob: 70ee1205c7c90067170c3113b3feea62fc242abf (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
75
76
77
78
79
80
81
;; /*
;; *	========================================================
;; *
;; *	ZKA
;; * 	Copyright ZKA Technologies., all rights reserved.
;; *
;; * 	========================================================
;; */

[bits 64]

[global rt_get_current_context]
[global rt_do_context_switch]
[global _hal_spin_core]
[extern _hal_switch_context]
[extern _hal_leak_current_context]

section .text

;; writes to rdx the stackframe inside rcx.
;; rcx: Stack Pointer
;; rdx: SMP core address.
rt_do_context_switch:
    push rax
    call _hal_switch_context
    pop rax

    ;; Now grab newly allocated process's stack frame.

    push rax
    call _hal_leak_current_context
    mov rax, r9
    pop rax

    ;; Take care of context switching within AP.

    mov r9, rax

    mov rbp, [r9 + (8 * 5)]
    mov rsp, [r9 + (8 * 6)]

    mov gs,  [r9 + (8 * 19)]
    mov fs,  [r9 + (8 * 20)]

    mov rcx, [r9 + (8 * 3)]
    mov rdx, [r9 + (8 * 4)]
    mov rbx, [r9 + (8 * 7)]
    mov rax, [r9 + (8 * 8)]
    movq xmm0, [r9 + (8 * 9)]
    movq xmm1, [r9 + (8 * 10)]

    mov r8, [r9 + (8 * 11)]
    mov r10, [r9 + (8 * 13)]
    mov r11, [r9 + (8 * 14)]
    mov r12, [r9 + (8 * 15)]
    mov r13, [r9 + (8 * 16)]
    mov r14, [r9 + (8 * 17)]
    mov r15, [r9 + (8 * 18)]

    fldcw word [r9 + (8 * 21)]

    mov r9, [r9 + (8 * 12)]

    retfq

;; gets the current stack frame.
rt_get_current_context:
    push rax

    call _hal_leak_current_context

    mov rax, r9
    pop rax

    mov r9, rax

    retfq

_hal_spin_core:
    jmp $
    ret