Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. org 7C00h
  2. jmp short bootmain
  3.  
  4. bootmain:
  5. xor ax, ax ; We want a segment of 0 for DS for this question
  6. mov ds, ax ; Set AX to appropriate segment value for your situation
  7. mov bx, 0x8000 ; Stack segment can be any usable memory
  8.  
  9. cli ; Disable interrupts to circumvent bug on early 8088 CPUs
  10. mov ss, bx ; Top of the stack @ 0x80000.
  11. mov sp, ax ; Set SP=0 so the bottom of stack will be just below 0x90000
  12. sti ; Re-enable interrupts
  13. cld ; Set the direction flag to be positive direction
  14.  
  15. mov ah, 0x02 ; Read sectors from drive
  16. mov al, 2 ; Read 1 sector
  17. mov ch, 0 ; Cylinder 0
  18. mov cl, 2 ; Sector 2
  19. mov dh, 0 ; Head 0
  20. mov bx, CODE_SEG
  21. mov es, bx ; ES = CODE_SEG
  22. xor bx, bx ; BX = 0
  23. int 0x13
  24.  
  25. cli
  26. lgdt [gdt_descriptor]
  27. mov eax, cr0
  28. or eax, 0x1
  29. mov cr0, eax
  30.  
  31. jmp CODE_SEG:prekernel_main
  32.  
  33. gdt_start:
  34. gdt_null:
  35. dd 0x0
  36. dd 0x0
  37. gdt_code:
  38. dw 0xffff
  39. dw 0x0
  40. db 0x0
  41. db 10011010b
  42. db 11001111b
  43. db 0x0
  44. gdt_data:
  45. dw 0xffff
  46. dw 0x0
  47. db 0x0
  48. db 10010010b
  49. db 11001111b
  50. db 0x0
  51. gdt_end:
  52. gdt_descriptor:
  53. dw gdt_end - gdt_start
  54. dd gdt_start
  55.  
  56. CODE_SEG equ gdt_code - gdt_start
  57. DATA_SEG equ gdt_data - gdt_start
  58.  
  59. [bits 32]
  60. prekernel_main:
  61. mov ax, DATA_SEG
  62. mov ds, ax
  63. mov es, ax
  64. mov fs, ax
  65. mov gs, ax
  66. mov ss, ax
  67.  
  68. mov ebp, 0x2000
  69. mov esp, ebp
  70. mov eax, 0xB8000
  71.  
  72. .loop:
  73. cmp eax, 0xB8FA0 ;0xB8000 + 4000
  74. je .end
  75. mov byte [eax], 'A'
  76. inc eax
  77. mov byte [eax], 0x07
  78. inc eax
  79. jmp .loop
  80.  
  81. .end:
  82. hlt
  83. jmp $
  84.  
  85. times 0200h - 2 - ($ - $$) db 0
  86. dw 0AA55h
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement