couple of bits on the x86_64 boot code
[newos.git] / boot / pc / x86_64 / smp_trampoline.S
blob480f453b57be2ca5c7cda81fcca32e7a84c9d452
1 /* 
2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
5 // expects a stack page like this:
6 // (stack has to be at (0x9e000)
7 //      0x9effc            : final esp
8 //  0x9eff8            : page dir
9 //
10 //  0x9e000 - 0x9e006  : gdt descriptor
11 //      0x9e008 - 0x9e020  : gdt
13 // smp_trampoline must be located at 0x9f000
14 .globl smp_trampoline
15 .globl smp_trampoline_end
16 .globl foo
18 .code16
19 smp_trampoline:
20         cli
21         
22         mov    $0x9e00,%ax
23         mov    %ax,%ds
25 //      lgdt   0x9e000          # load the gdt
26 .byte 0x66, 0x0f, 0x01, 0x15, 0x00, 0xe0, 0x09, 0x00
28         movl   %cr0,%eax
29         orl    $0x01,%eax
30         movl   %eax,%cr0              # switch into protected mode
32 .code32
33 _trampoline_32:
34         .byte 0x66
35         ljmp   $0x08,$(trampoline_32 - smp_trampoline + 0x9f000)
36 trampoline_32:
37         mov    $0x10, %ax
38         mov    %ax, %ds
39         mov    %ax, %es
40         mov    %ax, %fs
41         mov    %ax, %gs
42         mov    %ax, %ss
44         movl   $0x9eff8,%esp    # set up the stack pointer
46         popl   %eax             # get the page dir
47         movl   %eax,%cr3        # set the page dir
48         
49         popl   %eax             # get the final stack location
50         movl   %eax,%esp
52         // load an address for an indirect jump
53         movl   $trampoline_after_paging,%ecx
55         movl   %cr0,%eax
56         orl    $0x80000000,%eax
57         movl   %eax,%cr0          # enable paging
59         // jump to the address previously loaded. NOTE:
60         // this address is the address at which the code is originally linked,
61         // which is > 1MB. We will be out of the low memory at this point.
62         jmp    *%ecx
63 trampoline_after_paging:
64         // just return, the bsp would have set the return address to the
65         // target function at the top of the passed stack
66         ret
68 smp_trampoline_end: