]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/pc64/rebootcode.s
kernel: remove Ipifc.mbps, unused.
[plan9front.git] / sys / src / 9 / pc64 / rebootcode.s
1 #include "mem.h"
2
3 MODE $64
4
5 /*
6  * Turn off MMU, then memmove the new kernel to its correct location
7  * in physical memory.  Then jumps the to start of the kernel.
8  */
9
10 TEXT    main(SB), 1, $-4
11         MOVL    RARG, DI                /* destination */
12         MOVL    p2+8(FP), SI            /* source */
13         MOVL    n+16(FP), BX            /* byte count */
14
15         /* load zero length idt */
16         MOVL    $_idtptr64p<>(SB), AX
17         MOVL    (AX), IDTR
18
19         /* load temporary gdt */
20         MOVL    $_gdtptr64p<>(SB), AX
21         MOVL    (AX), GDTR
22
23         /* move stack below destination */
24         MOVL    DI, SP
25
26         /* load CS with 32bit code segment */
27         PUSHQ   $SELECTOR(3, SELGDT, 0)
28         PUSHQ   $_warp32<>(SB)
29         RETFQ
30
31 MODE $32
32
33 TEXT    _warp32<>(SB), 1, $-4
34
35         /* load 32bit data segments */
36         MOVL    $SELECTOR(2, SELGDT, 0), AX
37         MOVW    AX, DS
38         MOVW    AX, ES
39         MOVW    AX, FS
40         MOVW    AX, GS
41         MOVW    AX, SS
42
43         /* turn off paging */
44         MOVL    CR0, AX
45         ANDL    $0x7fffffff, AX         /* ~(PG) */
46         MOVL    AX, CR0
47
48         MOVL    $0, AX
49         MOVL    AX, CR3
50
51         /* disable long mode */
52         MOVL    $0xc0000080, CX         /* Extended Feature Enable */
53         RDMSR
54         ANDL    $0xfffffeff, AX         /* Long Mode Disable */
55         WRMSR
56
57         /* diable pae */
58         MOVL    CR4, AX
59         ANDL    $0xffffff5f, AX         /* ~(PAE|PGE) */
60         MOVL    AX, CR4
61
62         MOVL    BX, CX                  /* byte count */
63         MOVL    DI, AX                  /* save entry point */
64
65 /*
66  * the source and destination may overlap.
67  * determine whether to copy forward or backwards
68  */
69         CMPL    SI, DI
70         JGT     _forward
71         MOVL    SI, DX
72         ADDL    CX, DX
73         CMPL    DX, DI
74         JGT     _back
75
76 _forward:
77         CLD
78         REP;    MOVSB
79
80 _startkernel:
81         /* jump to entry point */
82         JMP*    AX
83
84 _back:
85         ADDL    CX, DI
86         ADDL    CX, SI
87         SUBL    $1, DI
88         SUBL    $1, SI
89         STD
90         REP;    MOVSB
91         JMP     _startkernel
92
93 TEXT _gdt<>(SB), 1, $-4
94         /* null descriptor */
95         LONG    $0
96         LONG    $0
97
98         /* (KESEG) 64 bit long mode exec segment */
99         LONG    $(0xFFFF)
100         LONG    $(SEGL|SEGG|SEGP|(0xF<<16)|SEGPL(0)|SEGEXEC|SEGR)
101
102         /* 32 bit data segment descriptor for 4 gigabytes (PL 0) */
103         LONG    $(0xFFFF)
104         LONG    $(SEGG|SEGB|(0xF<<16)|SEGP|SEGPL(0)|SEGDATA|SEGW)
105
106         /* 32 bit exec segment descriptor for 4 gigabytes (PL 0) */
107         LONG    $(0xFFFF)
108         LONG    $(SEGG|SEGD|(0xF<<16)|SEGP|SEGPL(0)|SEGEXEC|SEGR)
109
110 TEXT _gdtptr64p<>(SB), 1, $-4
111         WORD    $(4*8-1)
112         QUAD    $_gdt<>(SB)
113
114 TEXT _idtptr64p<>(SB), 1, $-4
115         WORD    $0
116         QUAD    $0