Commit initial
This commit is contained in:
8
boot/bootloader/Makefile
Normal file
8
boot/bootloader/Makefile
Normal file
@ -0,0 +1,8 @@
|
||||
.PHONY: clean
|
||||
all: bootsect.bin
|
||||
|
||||
bootsect.bin: bootsect.asm
|
||||
nasm -f bin -o $@ $^
|
||||
|
||||
clean:
|
||||
-rm -f bootsect.bin
|
173
boot/bootloader/bootsect.asm
Normal file
173
boot/bootloader/bootsect.asm
Normal file
@ -0,0 +1,173 @@
|
||||
; bootsect.asm - This file is a part of NutsOS
|
||||
|
||||
; NutsOS
|
||||
; Copyright (C) 2013 Free Software Foundation, Inc.
|
||||
|
||||
; NutsOS 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.
|
||||
|
||||
; NutsOS 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 NutsOS; If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
; Valentin Verdier <valentin.verdier03@gmail.com>
|
||||
|
||||
|
||||
|
||||
; Code placé dans le MBR du disque
|
||||
|
||||
; ####################################
|
||||
; BootLoader principal
|
||||
; ####################################
|
||||
|
||||
; Le code est copié par le BIOS à l'adresse 0x7C00, soit à la base du segment 0x07C0
|
||||
; 0x0:0x7C00 <=> 0x07C0:0000 0x07C0 x 0x10 = 0x7C00
|
||||
; adresse physique = segment x 16 + offset
|
||||
|
||||
%define BOOT_SEG 0x07C0
|
||||
%define KERN_LDR_SEG 0x07E0
|
||||
|
||||
%define KERN_LDR_LBA_ADDR 1
|
||||
|
||||
[BITS 16]
|
||||
[ORG 0] ; Par rapport au segment 0x07C0
|
||||
|
||||
boot:
|
||||
; On fait pointer les registres de segments sur le segment 0x07C0
|
||||
; On ne fait rien pour CS car le bios s'en ait déjà occupé
|
||||
mov ax, BOOT_SEG
|
||||
mov ds, ax
|
||||
|
||||
mov ax, 0x9F00 ; On définit l'adresse de base de la pile à la base du segment 0x9F00, soit à l'adresse 0x9F000
|
||||
mov ss, ax
|
||||
|
||||
mov sp, 0xFFF ; On définit le pointeur de pile à l'offset 0xFFFF ce qui correspond à l'adresse 0x9FFFF
|
||||
|
||||
mov [bootdisk], dl ; On sauvegarde le numéro de l'unité de disque utilisée par le BIOS
|
||||
|
||||
xor ax, ax ; int 0x13 fonction 0x00
|
||||
int 0x13
|
||||
|
||||
call load_kern_ldr
|
||||
|
||||
jmp KERN_LDR_SEG:0x0000 ; On saute vers le code de kernLdr
|
||||
|
||||
|
||||
; Fonction load_kern_ldr
|
||||
; Charge kernLdr qui commence au 30ème secteur du disque
|
||||
load_kern_ldr:
|
||||
push ax
|
||||
push ebx
|
||||
push dx
|
||||
push di
|
||||
|
||||
mov ax, 63 ; On charge 63 secteurs
|
||||
mov dx, KERN_LDR_SEG
|
||||
xor di, di
|
||||
mov ebx, KERN_LDR_LBA_ADDR
|
||||
|
||||
call build_DAPS
|
||||
call read_sector
|
||||
|
||||
pop di
|
||||
pop dx
|
||||
pop ebx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
; Fonction print
|
||||
; Params : pointeur sur str -> ds:si
|
||||
print:
|
||||
push ax
|
||||
push bx
|
||||
|
||||
.top:
|
||||
lodsb
|
||||
cmp al, 0
|
||||
jz .end
|
||||
|
||||
mov ah, 0x0E ; int 0x10 fonction 0x0E
|
||||
mov bx, 0x07 ; attribut du caractère
|
||||
int 0x10
|
||||
jmp .top
|
||||
|
||||
.end:
|
||||
pop bx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
|
||||
read_sector:
|
||||
push ax
|
||||
push dx
|
||||
push si
|
||||
|
||||
xor ax, ax
|
||||
add ax, 0 ; On met le flag de retenue à 0
|
||||
mov si, DAPS
|
||||
mov ah, 0x42
|
||||
mov dl, [bootdisk]
|
||||
int 0x13
|
||||
jc .error
|
||||
jmp .no_error
|
||||
|
||||
.error:
|
||||
mov si, error_int13h
|
||||
call print
|
||||
call stop
|
||||
|
||||
.no_error:
|
||||
pop si
|
||||
pop dx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
|
||||
; Fonction build_DAPS
|
||||
; Params: Nombre de secteur -> ax, Adresse LBA -> ebx, destination -> dx:di
|
||||
build_DAPS:
|
||||
mov [DAPS + 2], ax ; Nombre de secteurs
|
||||
|
||||
mov [DAPS + 4], di ; Offset du segment de destination
|
||||
mov [DAPS + 6], dx ; Segment de destination
|
||||
|
||||
; adresse LBA
|
||||
mov [DAPS + 8], ebx
|
||||
xor ax, ax
|
||||
mov [DAPS + 12], ax
|
||||
mov [DAPS + 14], ax
|
||||
ret
|
||||
|
||||
; Fonction Error
|
||||
stop:
|
||||
.loop:
|
||||
hlt
|
||||
jmp .loop
|
||||
|
||||
; Variables
|
||||
; ############################################
|
||||
|
||||
DAPS: ; Disk Address Packet Structure
|
||||
db 16 ; Taille de la structure
|
||||
db 0 ; Toujours à 0
|
||||
|
||||
dw 0 ; Nombre de secteurs à transfèrer
|
||||
|
||||
dw 0 ; Offset du segment de buffer
|
||||
dw 0 ; segment de buffer
|
||||
|
||||
dd 0 ; Adresse LBA de début
|
||||
dd 0 ; Partie haute de l'adresse LBA (pour LBA 48 bits) non utilisée ici
|
||||
|
||||
error_int13h: db "BIOS 13H extension error !", 13, 10, 0
|
||||
|
||||
boot_disk: db 0
|
||||
; ############################################
|
||||
|
||||
times 446-($-$$) db 144
|
Reference in New Issue
Block a user