Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;a.michelizza.free.fr
- %define BASE 0x100
- %define KSIZE 30
- [BITS 16]
- [ORG 0x0]
- jmp start
- %include "GDT.INC"
- start:
- ; init segments at 0x07C0
- mov ax, 0x07C0
- mov ds, ax
- mov es, ax
- mov ax, 0x8000
- mov ss, ax
- mov sp, 0xf000
- ; boot unit
- mov [bootdrv], dl
- ; load kernel
- xor ax, ax
- int 0x13
- push es
- mov ax, BASE
- mov es, ax
- mov bx, 0
- mov ah, 2
- mov al, KSIZE
- mov ch, 0
- mov cl, 2
- mov dh, 0
- mov dl, [bootdrv]
- int 0x13
- pop es
- ; init GDT see GDT.inc for functions and macros
- ; descInit base(32), limite(20/32), acces/type(8), flags(4/8), adresse(16)
- descInit 0, 0xFFFFF, 10011011b, 1101b, gdt_cs
- descInit 0, 0xFFFFF, 10010011b, 1101b, gdt_ds
- mov ax, gdtend
- mov bx, gdt
- sub ax, bx
- mov word [gdtptr], ax
- xor eax, eax
- mov ax, ds
- mov bx, gdt
- call calcadr
- mov dword [gdtptr+2], ecx
- ; switching to protected mode
- cli
- lgdt [gdtptr]
- mov eax, cr0
- or ax, 1
- mov cr0, eax
- jmp next
- next:
- mov ax, 0x10 ;data segment
- mov ds, ax
- mov fs, ax
- mov gs, ax
- mov es, ax
- mov ss, ax
- mov esp, 0x9F000
- call enable_A20
- jmp dword 0x8:0x1000
- end:
- jmp end
- enable_A20:
- call a20wait
- mov al,0xAD
- out 0x64,al
- call a20wait
- mov al,0xD0
- out 0x64,al
- call a20wait2
- in al,0x60
- push eax
- call a20wait
- mov al,0xD1
- out 0x64,al
- call a20wait
- pop eax
- or al,2
- out 0x60,al
- call a20wait
- mov al,0xAE
- out 0x64,al
- call a20wait
- ret
- a20wait:
- in al,0x64
- test al,2
- jnz a20wait
- ret
- a20wait2:
- in al,0x64
- test al,1
- jz a20wait2
- ret
- ;--------------------------------------------------------------------
- gdt:
- gdt_null:
- dw 0, 0, 0, 0
- gdt_cs:
- dw 0, 0, 0, 0
- gdt_ds:
- dw 0, 0, 0, 0
- gdtend:
- gdtptr:
- dw 0x0000 ; limit
- dd 0 ; base
- bootdrv: db 0
- ;--------------------------------------------------------------------
- times 510-($-$$) db 144
- dw 0xAA55
Advertisement
Add Comment
Please, Sign In to add comment