Advertisement
MichaelPetch

SO79535481 - boot.asm

Mar 26th, 2025 (edited)
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. [ORG 0x7C00]
  2. [BITS 16]
  3.  
  4. CODE_OFFSET equ 0x8
  5. DATA_OFFSET equ 0x10
  6.  
  7. KERNEL_POS equ 0x1000 ; 4096 bits dec, 512 bytes
  8. ; loader - 512 size bytes,
  9. ; then kernel will placed to 512
  10. _start:
  11. xor ax, ax
  12. mov es, ax
  13. mov ds, ax
  14. mov ss, ax
  15. mov sp, 0x7C00
  16. mov si, msg ; print message
  17. call PRINT
  18.  
  19. lgdt [gdt_descriptor]
  20.  
  21. read_kernel:
  22. mov bx, KERNEL_POS
  23. mov dl, 0x80 ; always to int 0x13
  24. mov cl, 0x02 ; second sector(each 512 bytes)
  25. mov ch, 0x00 ; first cylinder
  26. mov ah, 0x02 ; read
  27. mov al, 8 ; 8 sectors to read
  28. int 0x13
  29.  
  30. prot_mode_switch:
  31. cli
  32. mov eax, cr0
  33. or eax, 0x01
  34. mov cr0, eax
  35. jmp CODE_OFFSET:prot_mode_main
  36.  
  37. PRINT:
  38. mov ah, 0x0E
  39. mov al, [si]
  40. cmp al, 0
  41. jz .end
  42. inc si
  43. int 0x10
  44. jmp PRINT
  45. .end:
  46. ret
  47.  
  48.  
  49. gdt_start:
  50. ; NULL descriptor
  51. dd 0x00000000
  52. dd 0x00000000
  53.  
  54. ;KERNEL MODE:
  55.  
  56. ;code segment (0x8)
  57. dw 0xFFFF ; Limit
  58. dw 0x0000 ; Base
  59. db 0x00 ; Base
  60. db 0b10011010 ; Access byte
  61. db 0b11001111 ; Flags
  62. db 0x00 ; Base
  63.  
  64. ;data segment (0x10)
  65. dw 0xFFFF ; Limit
  66. dw 0x0000 ; Base
  67. db 0x00 ; Base
  68. db 0b10010010 ; Access byte
  69. db 0b11001111 ; Flags
  70. db 0x00 ; Base
  71.  
  72. gdt_end:
  73. gdt_descriptor:
  74. dw gdt_end - gdt_start - 1 ; size - 1
  75. dd gdt_start
  76.  
  77. [BITS 32]
  78.  
  79. prot_mode_main:
  80. mov sp, 0x9C00 ; initialize stack for prot mode
  81. mov bp, sp
  82. mov ax, 0x10 ; initialize segment registers
  83. mov ds, ax ; for prot mode
  84. mov ss, ax
  85. mov fs, ax
  86. mov gs, ax
  87. mov es, ax
  88.  
  89. in al, 0x92 ; enabling a20 line
  90. or al, 0x2
  91. out 0x92, al
  92. hlt
  93.  
  94.  
  95. msg: db "Booting", 0
  96. test: db "Test", 0
  97. TIMES 510-($-$$) db 0x00
  98. dw 0xaa55
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement