os-k/src/boot/mbr.s

129 lines
4.3 KiB
ArmAsm
Raw Normal View History

;=----------------------------------------------------------------------------=;
; GNU GPL OS/K ;
; ;
; Authors: spectral` ;
; NeoX ;
; ;
; Desc: Master Boot Record for OS/K ;
; (x86_64 architecture only) ;
;=----------------------------------------------------------------------------=;
[BITS 16] ; real mode
[ORG 0x7C00] ; address where the BIOS/UEFI CSM is loading us
jmp 0x0000:Start ; far-jump to avoid loading address issues with older BIOSes
; some older BIOSes could load bootloader.bin at 0x7C00:0x0000
; while newer ones would load it at 0x0000:0x7C00...
; here the far-jump sets CS to 0
bootdb db 'GNUOS/K ' ;Fabricant + n°série Formatage
sizec dw 512 ;octet/secteur
db 1 ;secteur/cluster
reserv dw 1 ;secteur reserv‚
nbfat db 2 ;nb de copie de la FAT
nbfit dw 224 ;taille rep racine
allclu dw 2880 ;nb secteur du volume si < 32 még
db 0F0h ;Descripteur de média
fatsize dw 9 ;secteur/FAT
nbtrack dw 18 ;secteur/piste
head dw 2 ;nb de tˆteb de lecture/écriture
hidden dd 0 ;nombre de secteur cach‚s
dd 0 ;si nbsecteur = 0 nbsect ; the number of sectors
bootdrv db 0 ;Lecteur de d‚marrage
bootsig db 0 ;NA
db 29h ;boot signature 29h
bootsig2 dd 01020304h ;no de serie
pope db 'COS2000 ' ;nom de volume
db 'FAT12 ' ;FAT
;; DATA
Bootdrv db 0x00
Starting db 0x0A, 0x0D, 0x07, " GNU GPL OS/K ", 0x0A, 0x0D, 0x0A, 0x0D, 0
NoLongMode db 0x0A, 0x0D, "ERROR: Your computer is not designed for x64 OS", 0
A20ERR db 0x0A, 0x0D, "ERROR: Failed to enable A20 line!", 0
SwErr db 0x0A, 0x0D, "ERROR: Loading failed!", 0
Init db 0x09, " Checking CPUID", 0
EnA20 db 0x09, " Enabling A20 line", 0
Switch db 0x09, " Loading Second Stage", 0
Pass db " OK", 0x0A, 0x0D, 0
%define SECOND_STAGE 0x100
;; INCLUDES
%include "boot/mbr.inc" ; for Is64Bits
%include "boot/common.inc" ; for PrintB
Start:
pushad
pushfd
pushf
mov [Bootdrv], dl ; dl contains the boot drive. Saving it.
;; hello world
push si
mov si, Starting
call PrintB
;; compatibility check
mov si, Init
call PrintB
pop si
call Is64bits ; in mbr.inc
jc ErrorNo64
push si
mov si, Pass
call PrintB
;; enabling A20
mov si, EnA20
call PrintB
pop si
in al, 0x92
or al, 2
out 0x92, al
jc A20Fail
push si
mov si, Pass
call PrintB
;; switch to second stage
mov si, Switch
call PrintB
pop si
;; Reset floppy drive and load second stage
call LoadSec ; Loading from boot disk
jc SwFail
popf
popfd
popad
mov ax, [Bootdrv]
push ax
jmp dword SECOND_STAGE:0000 ; Jumping to second stage loader.
;;END OF MBR
;;----------------------------------------------------------------------------;;
A20Fail:
mov si, A20ERR
call PrintB
jmp Die
SwFail:
mov si, SwErr
call PrintB
jmp Die
ErrorNo64:
mov si, NoLongMode
call PrintB
Die:
cli
hlt ; die nooooow
jmp Die
End:
times 510-($-$$) db 144 ; NOP until 510
dw 0xAA55 ; magic word