ap_tramp.S 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * AP startup trampoline, linked at 0x6000 and copied there by the BSP.
  3. *
  4. * The BSP fills the fixed info block at 0x6F00 before sending SIPI:
  5. * 0x6F00 cr3 (physical kernel page directory)
  6. * 0x6F04 stack_top (AP idle stack top, identity mapped)
  7. * 0x6F08 entry (C entry point, protected-mode address)
  8. * 0x6F0C cpu_index
  9. *
  10. * The AP starts in real mode at 0x6000 (SIPI vector 0x06), builds a tiny flat
  11. * GDT, enters protected mode, enables PSE + paging and jumps to the C entry.
  12. */
  13. .code16
  14. .section .text.ap, "ax"
  15. .equ AP_INFO, 0x6F00
  16. .equ AP_INFO_CR3, AP_INFO + 0
  17. .equ AP_INFO_STACK, AP_INFO + 4
  18. .equ AP_INFO_ENTRY, AP_INFO + 8
  19. .equ AP_INFO_CPU, AP_INFO + 12
  20. .globl ap_tramp_start
  21. ap_tramp_start:
  22. cli
  23. cld
  24. xorw %ax, %ax
  25. movw %ax, %ds
  26. movw %ax, %es
  27. movw %ax, %fs
  28. movw %ax, %gs
  29. movw %ax, %ss
  30. movw $0x6C00, %sp
  31. lgdt ap_gdt_desc
  32. movl %cr0, %eax
  33. orl $1, %eax
  34. movl %eax, %cr0
  35. /* 32-bit far jump into the protected-mode part. */
  36. .byte 0x66, 0xea
  37. .long ap_pm32
  38. .word 0x08
  39. .code32
  40. ap_pm32:
  41. movw $0x10, %ax
  42. movw %ax, %ds
  43. movw %ax, %es
  44. movw %ax, %fs
  45. movw %ax, %gs
  46. movw %ax, %ss
  47. movl AP_INFO_STACK, %esp
  48. movl AP_INFO_CR3, %eax
  49. movl %eax, %cr3
  50. movl %cr4, %eax
  51. orl $0x10, %eax /* CR4.PSE */
  52. movl %eax, %cr4
  53. movl %cr0, %eax
  54. orl $0x80010000, %eax /* CR0.PG | CR0.WP */
  55. movl %eax, %cr0
  56. jmp 1f
  57. 1:
  58. movl AP_INFO_CPU, %eax
  59. pushl %eax
  60. movl AP_INFO_ENTRY, %eax
  61. call *%eax
  62. 2: cli
  63. hlt
  64. jmp 2b
  65. .align 8
  66. ap_gdt:
  67. .quad 0
  68. .word 0xFFFF, 0x0000
  69. .byte 0x00, 0x9A, 0xCF, 0x00
  70. .word 0xFFFF, 0x0000
  71. .byte 0x00, 0x92, 0xCF, 0x00
  72. ap_gdt_end:
  73. ap_gdt_desc:
  74. .word ap_gdt_end - ap_gdt - 1
  75. .long ap_gdt