
[BITS 16]
[ORG 0x7c00]
    
   jmp 0:start 
   driveno db 0
a  db 'welcome to boot sector', 13,10,0 
b  db 'downloaded sector 2,3 at 1000h', 13,10,0
c db  'helloo a20',13,10,0  
 
 start:
       
        mov ax,0
        mov ds ,ax
        
        mov ss,ax
        mov sp,0x9000
        mov [driveno],dl
      
        mov si,a
       call message 
     
       push ax
       call enable_a20
       pop ax 
       mov ax ,0
       mov es,ax
       mov bx,0x1000
                         
      
read_kn:
      
      call read_sector
                    
       mov si,a
       call message
                    
       mov si ,b
       call message 
       
        cli   
        mov ax,0
        mov ds , ax
          lgdt [GDT]
     ;;turn on protected mode 
         mov eax,cr0
         or eax,1
         mov cr0,eax

     jmp      0x08: protected_mode
       
enable_a20:
           mov ax,0x2401       ; enable a20 is wrking
           int 0x15 
               ;jc .abc       
                                 
               ;mov si ,c
               ;call message
           
       .abc: ret   
 
[BITS 32]

g db 'protected mode',13,10,0

protected_mode:
        mov ax,0x10
        mov ds,ax
        mov ss,ax
        mov esp,0x200000  
        
        mov esi , g            ;;this is not shown on output         
        call PutStr_32
        jmp  0x08:0x1000
       stop : jmp stop

PutStr_32:     
    mov edi, [PutStr_Ptr]
.nextchar:
    lodsb
    test al, al         
    jz .end     
    stosw
    jmp .nextchar 
  .end:
    mov [PutStr_Ptr], edi
    ret 

PutStr_Ptr dd 0xb8000


[BITS 16]
read_sector:  
             push ax
             push cx
              push dx
             
                        
                        ;inc ax
            mov cx,2    ; ch= cylinder cl= sector 
           xor dx,dx    ; dh= head= 0
                        
          mov dl,[driveno]  ; dl = drive no   
                      
          mov al,2
           mov ah,2
         int 0x13
          pop dx
          pop cx 
          pop ax
          ret  
message:                        ; Dump ds:si to screen.
                lodsb                   ; load byte at ds:si into al
                or al,al                ; test if character is 0 (end)
                jz done
                mov ah,0eh              ; put character
                mov bx,0007             ; attribute
                int 0x10                ; call BIOS
                jmp message
        done:
                ret

GDT:		dw gdt_limit ; null segment, used to store GDT metadata
		dd GDT
		dw 0

	.cseg:	dd 0x0000FFFF, 0x00CF9a00 ; code segment, 32-bit, 0  ;4GB
	.dseg:	dd 0x0000FFFF, 0x00CF9200 ; data segment, 32-bit, 0 ;to 4GB

	gdt_limit equ $-GDT-1


; --------------------------
; boot seal
; --------------------------
[bits 16]
times 512-($-$$)-2	db	0x00
	dw	0xaa55
