apu_boot.S 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "../common/asm.h"
  2. .align 0x1000 // 按照4k对齐
  3. .section .text
  4. .code16
  5. ENTRY(_apu_boot_start)
  6. _apu_boot_base = .
  7. cli
  8. wbinvd // 将处理器缓存同步到内存中
  9. mov %cs, %ax
  10. mov %ax, %ds
  11. mov %ax, %es
  12. mov %ax, %ss
  13. mov %ax, %fs
  14. mov %ax, %gs
  15. // 设置栈指针
  16. movl $(_apu_boot_tmp_stack_end - _apu_boot_base), %esp
  17. // 计算ap处理器引导程序的基地址
  18. mov %cs, %ax
  19. movzx %ax, %esi
  20. shll $4, %esi
  21. // set gdt and 32bit/64bit code addr
  22. leal (_apu_code32 - _apu_boot_base)(%esi), %eax
  23. movl %eax, (_apu_code32_vector - _apu_boot_base)
  24. leal (_apu_code64 - _apu_boot_base)(%esi), %eax
  25. movl %eax, (_apu_code64_vector - _apu_boot_base)
  26. leal (_apu_tmp_gdt - _apu_boot_base)(%esi), %eax
  27. movl %eax, (_apu_tmp_gdt + 2 - _apu_boot_base)
  28. // 从实模式切换到保护模式
  29. lidtl _apu_tmp_idt - _apu_boot_base
  30. lgdtl _apu_tmp_gdt - _apu_boot_base
  31. // 操作cr0控制器,使能保护模式
  32. smsw %ax
  33. bts $0, %ax
  34. lmsw %ax
  35. // 转到保护模式
  36. ljmpl *(_apu_code32_vector - _apu_boot_base)
  37. .code32
  38. .align 0x1000
  39. _apu_code32:
  40. # 转到长模式
  41. mov $0x10, %ax
  42. mov %ax, %ds
  43. mov %ax, %es
  44. mov %ax, %ss
  45. mov %ax, %fs
  46. mov %ax, %gs
  47. // 设置栈指针
  48. leal (_apu_boot_tmp_stack_end - _apu_boot_base)(%esi), %eax
  49. movl %eax, %esp
  50. // 1. 允许 PAE
  51. mov %cr4, %eax
  52. or $(1<<5), %eax
  53. mov %eax, %cr4
  54. movl $enter_head_from_ap_boot, %eax
  55. jmpl *%eax
  56. hlt
  57. .code64
  58. .align 0x1000
  59. _apu_code64:
  60. hlt
  61. .align 0x1000
  62. _apu_tmp_idt:
  63. .word 0
  64. .word 0,0
  65. .align 0x1000
  66. _apu_tmp_gdt:
  67. .short _apu_tmp_gdt_end - _apu_tmp_gdt -1
  68. .long _apu_tmp_gdt - _apu_boot_base
  69. .short 0
  70. .quad 0x00cf9a000000ffff
  71. .quad 0x00cf92000000ffff
  72. .quad 0x0020980000000000
  73. .quad 0x0000920000000000
  74. _apu_tmp_gdt_end:
  75. .align 0x1000
  76. _apu_code32_vector:
  77. .long _apu_code32 - _apu_boot_base
  78. .word 0x08,0
  79. .align 0x1000
  80. _apu_code64_vector:
  81. .long _apu_code64 - _apu_boot_base
  82. .word 0x18,0
  83. .align 0x1000
  84. _apu_boot_tmp_stack_start:
  85. // .org 0x400
  86. _apu_boot_tmp_stack_end:
  87. ENTRY(_apu_boot_end)