Advertisement
seb15753

bootsect.asm

Jun 22nd, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;originally found at http://a.michelizza.free.fr
  2. [BITS 16]
  3. [ORG 0x0]
  4.  
  5. jmp start
  6.  
  7. %include "GDT.INC"
  8.  
  9. start:
  10.  
  11. ; init of segments registers to 0x07C0
  12.     mov ax, 0x07C0
  13.     mov ds, ax
  14.  
  15. ; load kernel into RAM
  16.     xor ax, ax
  17.     int 0x13
  18.  
  19.     mov ax, 0x100
  20.     mov es, ax
  21.     mov bx, 0
  22.  
  23.     mov ah, 2
  24.     mov al, 1 ; 1 sector
  25.     mov ch, 0
  26.     mov cl, 2
  27.     mov dh, 0
  28.     int 0x13
  29.  
  30.  
  31. ; init GDT cf GDT.INC
  32. ;code and data segments just differs from one bit.
  33. ; base and limit are the same for code and data segment (0 to 4Gio)
  34.  
  35.     descInit 0, 0xFFFFF, 10011011b, 1101b, gdt_cs
  36.     descInit 0, 0xFFFFF, 10010011b, 1101b, gdt_ds
  37.  
  38.     mov ax, gdtend    ; compute GTD limit
  39.     mov bx, gdt
  40.     sub ax, bx
  41.     mov word [gdtptr], ax
  42.  
  43.     xor eax, eax    ; compute linear @ of GDT
  44.     mov  ax, ds
  45.     mov  bx, gdt
  46.     call calcadr
  47.     mov dword [gdtptr+2], ecx
  48.  
  49. ; switching to protected mode
  50.     cli
  51.     lgdt [gdtptr]    ; load gdt
  52.     mov eax, cr0
  53.     or   ax, 1
  54.     mov cr0, eax    ; active Proected mode
  55.  
  56.     jmp next
  57. next:
  58.     mov ax, 0x10    ; data segment in GDT
  59.     mov ds, ax
  60.  
  61.     jmp dword 0x8:0x1000
  62.  
  63. ;end:
  64. ;    jmp end
  65.  
  66.  
  67. ;---data-----------------------------------------------------------------
  68.  
  69. gdt:
  70. gdt_null:
  71.     dw 0, 0, 0, 0
  72. gdt_cs:
  73.     dw 0, 0, 0, 0
  74. gdt_ds:
  75.     dw 0, 0, 0, 0
  76. gdtend:
  77.  
  78. gdtptr:
  79.     dw    0x0000    ; limite
  80.     dd    0         ; base
  81.  
  82. bootdrv: db 0
  83.  
  84. ;--------------------------------------------------------------------
  85. ;; NOP jusqu'a 510
  86. times 510-($-$$) db 144
  87. dw 0xAA55
  88.  
  89.                                                                                                                              87,0-1        Bas
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement