Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. .set PROT_MODE_CSEG, 0x8
  2. .set PROT_MODE_DSEG, 0x10
  3. .set CR0_PE_ON, 0x1
  4.  
  5. .globl start
  6. start:
  7. .code16
  8.  
  9. cli # Disable interrupts
  10. cld # String operations increment the counter
  11.  
  12. # Switch from 16-bit real mode to 32-bit protected mode
  13. lgdt gdtdesc
  14. movl %cr0, %eax
  15. orl $CR0_PE_ON, %eax
  16. movl %eax, %cr0
  17. ljmp $PROT_MODE_CSEG, $protcseg
  18.  
  19. gdt:
  20. # Null segment
  21. .word 0, 0
  22. .byte 0, 0, 0, 0
  23. # Code segment
  24. .word 0xffff
  25. .word 0x0
  26. .byte 0x0
  27. .byte 0b10011010
  28. .byte 0b11001111
  29. .byte 0x0
  30. # Data segment
  31. .word 0xffff
  32. .word 0x0
  33. .byte 0x0
  34. .byte 0b10010010
  35. .byte 0b11001111
  36. .byte 0x0
  37. gdtdesc:
  38. .word 0x17
  39. .long gdt
  40.  
  41. .code32
  42. protcseg:
  43. # Setup the 32-bit protected mode data segment registers
  44. movw $PROT_MODE_DSEG, %ax
  45. movw %ax, %ds
  46. movw %ax, %es
  47. movw %ax, %fs
  48. movw %ax, %gs
  49. movw %ax, %ss
  50.  
  51. # Setup the stack pointer and call into C
  52. movl $start, %esp
  53. call bootmain
  54.  
  55. spin:
  56. jmp spin # If bootmain returns, loop infinitely
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement