Guest User

SMP trampoline code

a guest
Oct 8th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. section .text
  2. BITS 16
  3. global _start_smp
  4. extern smp_done
  5. _start_smp:
  6.     cli ;ensure that interrupts are disabled
  7.     lgdt [0x0 + (_gdtr_begin - _start_smp)]
  8.     mov eax, cr0
  9.     or al, 1
  10.     mov cr0, eax
  11.     xor eax, eax
  12.     mov ax, 0x10
  13.     mov ss, ax
  14.     mov ds, ax
  15.     mov gs, ax
  16.     mov fs, ax
  17.     mov es, ax
  18.     jmp 0x08:(0x0 + (__long_mode_enter - _start_smp))
  19. __long_mode_enter:
  20.     BITS 32
  21.     extern pml4
  22.     ;Load the kernel's pml4
  23.     mov eax, pml4
  24.     mov cr3, eax
  25.     ;Enable PAE
  26.     mov eax, cr4
  27.     or eax, 1 << 5
  28.     mov cr4, eax
  29.     ; Enable Long Mode in the MSR
  30.     ; Use this to perform some initialization of features
  31.     ; we might need
  32.     mov ecx, 0xC0000080
  33.     rdmsr
  34.     or eax, 1 ; enable syscall/sysret
  35.     or eax, 1 << 8 ; enable long mode
  36.     or eax, 1 << 11 ; enable NX
  37.     wrmsr
  38.  
  39.     ; Enable Paging
  40.     mov eax, cr0
  41.     or eax, 1 << 31
  42.     mov cr0, eax
  43.     lgdt [0x0 + (_gdtr2_begin - _start_smp)]
  44.     mov esp, 0x2000
  45.     push 0x08
  46.     push 0x0 + (_long_mode - _start_smp)
  47.     retf
  48. _long_mode:
  49. BITS 64
  50.     mov eax, 0x10
  51.     mov ds, ax
  52.     mov es, ax
  53.     mov ss, ax
  54.     ; Load the common gdt between all cores
  55.     extern gdtr3
  56.     lgdt [gdtr3]
  57.     extern idt_ptr
  58.     lidt [idt_ptr]
  59.     extern core_stack
  60.     mov rsp, [core_stack]
  61.     ;extern initsse
  62.     ;call initsse
  63.     ; Say to the BSP that we finished
  64.     extern ap_done
  65.     mov dword [ap_done], 1
  66.     extern idle_smp
  67.     ;jmp idle_smp
  68. halt:
  69.     hlt
  70. jmp halt
  71.  
  72. global _smp_func_end
  73. _smp_func_end:
  74. gdt:
  75.     DQ  0x0000000000000000
  76.     DQ  0x00CF9A000000FFFF
  77.     DQ  0x00CF92000000FFFF
  78. gdtl:
  79.     DQ  0x0000000000000000
  80.     DQ  0x00A09A0000000000
  81.     DQ  0x00A0920000000000
  82.     DQ  0x00A0FA0000000000
  83.     DQ  0x00A0F20000000000
  84. tss_gdt:
  85.     DW  0x67,0
  86.     DB  0, 0xE9, 0
  87.     DB  0
  88.     DD  0
  89.  
  90. _gdtr_begin:
  91. gdtr:
  92.     DW  40
  93.     DD  0x0 + (_smp_func_end - _start_smp)
  94. _gdtr2_begin:
  95. gdtr2:
  96.     DW 40
  97.     DD 0x0 + (gdtl - _start_smp)
  98. global _end_smp
  99. _end_smp:
Advertisement
Add Comment
Please, Sign In to add comment