Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

123 Zeilen
2.2 KiB

  1. ; Boot sector, freely inspired by http://jojo.ouvaton.org/dossiers/boot_sector/tutorial02.html
  2. ; Sets a GDT and protected mode
  3. ; Copy the kernel (or stage2) to 0x1000 (linear)
  4. ; Max kernel size is 25600 bytes (50 sectors)
  5. %define BASE 0x100 ; 0x0100:0x0 = 0x1000
  6. %define KSIZE 50
  7. [BITS 16]
  8. [ORG 0x0]
  9. ; Code starts here, jump to our real entry point, skipping print
  10. jmp start
  11. ; print string using BIOS
  12. print:
  13. push ax
  14. push bx
  15. .start:
  16. lodsb ; ds:si -> al
  17. cmp al,0
  18. jz .fin
  19. mov ah,0x0E ; 0x0e function of BIOS 0x10 interruption
  20. mov bx,0x07 ; bx -> attribute, al -> ascii
  21. int 0x10
  22. jmp .start
  23. .fin:
  24. pop bx
  25. pop ax
  26. ret
  27. ; Entry point
  28. start:
  29. mov [bootdrv],dl ; boot drive
  30. ; Stack and section initialization at 0x07C0
  31. mov ax,0x07C0
  32. mov ds,ax
  33. mov es,ax
  34. mov ax,0x8000 ; stack at 0xFFFF
  35. mov ss,ax
  36. mov sp, 0xf000
  37. ; print 'Loading kernel ...'
  38. mov si, ldKernel
  39. call print
  40. ; Load kernel
  41. xor ax,ax
  42. int 0x13
  43. push es
  44. mov ax,BASE
  45. mov es,ax
  46. mov bx,0
  47. mov ah,2
  48. mov al,KSIZE
  49. mov ch,0
  50. mov cl,2
  51. mov dh,0
  52. mov dl,[bootdrv]
  53. int 0x13
  54. pop es
  55. ; GDT pointer
  56. mov ax,gdtend ; GDT limit
  57. mov bx,gdt
  58. sub ax,bx
  59. mov word [gdtptr],ax
  60. xor eax,eax ; GDT linear address
  61. xor ebx,ebx
  62. mov ax,ds
  63. mov ecx,eax
  64. shl ecx,4
  65. mov bx,gdt
  66. add ecx,ebx
  67. mov dword [gdtptr+2],ecx
  68. ; pmode
  69. cli
  70. lgdt [gdtptr] ; load GDT
  71. mov eax, cr0
  72. or ax,1
  73. mov cr0,eax ; enter Protected Mode
  74. jmp next
  75. next:
  76. mov ax,0x10 ; data segment
  77. mov ds,ax
  78. mov fs,ax
  79. mov gs,ax
  80. mov es,ax
  81. mov ss,ax
  82. mov esp,0x9F000
  83. jmp dword 0x8:0x1000 ; jump to kernel _start at 0x1000 of 'second' selector (*8)
  84. ;--------------------------------------------------------------------
  85. bootdrv: db 0
  86. ldKernel db "Loading kernel ...",13,10,0
  87. ;--------------------------------------------------------------------
  88. gdt:
  89. db 0,0,0,0,0,0,0,0
  90. gdt_cs:
  91. db 0xFF,0xFF,0x0,0x0,0x0,10011011b,11011111b,0x0
  92. gdt_ds:
  93. db 0xFF,0xFF,0x0,0x0,0x0,10010011b,11011111b,0x0
  94. gdtend:
  95. ;--------------------------------------------------------------------
  96. gdtptr:
  97. dw 0 ; limit
  98. dd 0 ; base
  99. ;--------------------------------------------------------------------
  100. ;; fill remaining space with NOPs
  101. times 510-($-$$) db 144
  102. dw 0xAA55