x86_gcc.S 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-07-13 JasonHu first version
  9. */
  10. #define __ASSEMBLY__
  11. #include "segment.h"
  12. .global load_new_gdt
  13. load_new_gdt:
  14. movl 4(%esp), %eax
  15. movw %ax, 6(%esp)
  16. lgdt 6(%esp)
  17. # flush segment registers
  18. movw $KERNEL_DATA_SEL, %ax
  19. movw %ax, %ds
  20. movw %ax, %es
  21. movw %ax, %ss
  22. xor %eax, %eax
  23. movw %ax, %fs
  24. movw %ax, %gs
  25. ljmp $KERNEL_CODE_SEL, $.newpc
  26. .newpc:
  27. ret
  28. .global load_new_idt
  29. load_new_idt:
  30. movl 4(%esp), %eax
  31. movw %ax, 6(%esp)
  32. lidt 6(%esp)
  33. ret
  34. .global write_cr3
  35. write_cr3:
  36. movl 4(%esp), %eax
  37. movl %eax, %cr3
  38. ret
  39. .global read_cr0
  40. read_cr0:
  41. movl %cr0, %eax
  42. ret
  43. .global read_cr2
  44. read_cr2:
  45. movl %cr2, %eax
  46. ret
  47. .global write_cr0
  48. write_cr0:
  49. movl 4(%esp), %eax
  50. movl %eax, %cr0
  51. ret