View of xos/boot/setup.asm


XOS | Parent Directory | View | Download

; Copyright (C) 2008  Emmanuel Varoquaux
;
; This file is part of XOS.
;
; This program is free software: you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program.  If not, see <http://www.gnu.org/licenses/>.

; Setup
;
; setup.bin est charge par le secteur de boot. Il en constitue une extension,
; dans la mesure ou le secteur de boot est trop petit pour contenir tout le
; code qu'il devrait executer.
;
; setup.bin passe en mode protege et execute le systeme.

%define SYS_SEG	0x1000		; segment de chargement du systeme

	bits	16
	org	0x200

	push	ax
	mov	ax,ds
	mov	es,ax
	cli			; pas d'interruptions

; Chargement de l'IDT et de la GDT
	lidt	[idt_descr]
	lgdt	[gdt_descr]

; Activation de la ligne d'adresse A20
; cf http://www.win.tue.nl/~aeb/linux/kbd/A20.html
	call	empty_8042
	mov	al,0xd1		; ecriture de la commande
	out	0x64,al
	call	empty_8042
	mov	al,0xdf		; activation de A20
	out	0x60,al
	call	empty_8042

; Recuperation du nombre de secteurs charges
	pop	bx

; Passage en mode protege
	mov	eax,cr0
	or	ax,1
	mov	cr0,eax
	jmp	next		; vidage de la file d'instructions
next:

; Transfert de l'execution au systeme
	mov	ax,0x10
	mov	ds,ax
	mov	es,ax
	mov	fs,ax
	mov	gs,ax
	mov	ss,ax
	mov	ax,bx
	and	eax,0x0000ffff
	shl	eax,9
	jmp	dword 0x8:SYS_SEG << 4

; Cette routine attend que la file des commandes du clavier soit vide.
; Modifie al.
empty_8042:
	dw	0x00eb,0x00eb
	in	al,0x64
	test	al,2
	jnz	empty_8042
	ret

; Variables

; Global Descriptor Table
gdt:
	dw	0,0,0,0		; descripteur nul

	dw	0xffff		; segment de code (4Go)
	dw	0x0000
	dw	0x9a00
	dw	0x00cf

	dw	0xffff		; segment de donnees (4Go)
	dw	0x0000
	dw	0x9200
	dw	0x00cf

idt_descr:
	dw	0		; limit=0
	dw	0,0		; base=0

gdt_descr:
	dw	0x800		; limit=2048 (256 entrees)
	dw	0x7c00+gdt,0	; base=0x7c00+gdt