%define	BASE	0x100	; 0x0100:0x0 = 0x1000
%define KSIZE	3 
%define BOOT_SEG 0x07c0

BITS 16
ORG 0x0

; initialisation des segments en 0x07C0
	mov ax,BOOT_SEG
	mov ds,ax
	mov es,ax
	mov ax,0x8000	; stack en 0xFFFF
	mov ss,ax
	mov sp, 0xf000

; affiche un msg
	mov si,msgDebut
	call afficher

; charger le noyau
	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 ;DL contient déjà le numéro du lecteur
	int 0x13
	pop es

; passage en modep
	cli
	lgdt [gdtptr]	; charge la gdt
	mov eax,cr0
	or ax,1
	mov cr0,eax		; PE mis a 1 (CR0)

	jmp next
next:
	mov ax,0x10		; segment de données
	mov ds,ax
	mov fs,ax
	mov gs,ax
	mov es,ax
	mov ss,ax
	mov esp,0x9F000	

	jmp dword 0x8:BASE << 4; réinitialise le segment de code

%include "UTIL.INC"

;--------------------------------------------------------------------
;bootdrv: db 0
msgDebut	db	"Chargement du kernel",13,10,0

;--------------------------------------------------------------------
gdt:
	db 0,0,0,0,0,0,0,0
gdt_cs:
	db 0xFF,0xFF,0x0,0x0,0x0,10011011b,11011111b,0x0
gdt_ds:
	db 0xFF,0xFF,0x0,0x0,0x0,10010011b,11011111b,0x0
gdtend:

;--------------------------------------------------------------------
gdtptr:
	dw	gdtend-gdt				; limite
	dd	(BOOT_SEG << 4) + gdt	; base

;--------------------------------------------------------------------
;; NOP jusqu'a 510
times 510-($-$$) db 0
dw 0xAA55
