;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Copyrights(C) 2005, 2006 by Sohail Qayum Malik;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;bootblok.asm(The boot-sector code). ;; ;;Written by, Sohail Qayum Malik ;; ;; ;; ;;DL = drive-id of the device we booted from. ;; ;;DH = head-number of the device we booted from. ;; ;;ES:SI = in case of HD boot the segmented address of the partition table's ;; ;; active partition table entry. ;; ;; ;; ;;This programm will load the secondry boot code at 0x1000:0000. ;; ;;The secondry boot programm will transfer it self high, then execution ;; ;;will be in the high memory area. ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SPOFFSET equ 7c00h ;LOADOFFSET equ 7c3eh SECTORSSEGMENT equ 0000h SECTORSOFFSET equ 7e00h KERNELSEGMENT equ 1000h KERNELOFFSET equ 0000h ;KERNELOFFSET1 equ 0100h ;KERNELSEGMENT equ 0ffffh ;KERNELOFFSET equ 00010h CR equ 0dh LF equ 0ah EOL equ 00h ;Okhey we are at 0000:7c00, the first 62 bytes are the DOS specific bytes ;so our code starts at the following location counter. org 7c3eh ;Jump to the _start jmp _start ;DATA logo db CR,LF,'Booting YAN....',EOL MHLT db CR,LF,CR,LF,'System halted.',EOL KSR db CR,LF,"Secondry boot loader's sector ID's read.",EOL KCR db CR,LF,'Loading secondry boot loader low.',CR,LF,EOL shit db '*',EOL MA20 db CR,LF,'A20 line enabled.',EOL rderr db CR,LF,"Read error ",EOL errno db "00 ",EOL _enableA20: pusha cli mov cx, 05h _attempt: call _commandwait mov al, 0d0h out 64h, al call _datawait xor ax, ax in al, 60h push ax call _commandwait mov al, 0d1h out 64h, al call _commandwait pop ax or al, 00000010b out 60h, al call _commandwait mov al, 0d0h out 64h, al call _datawait xor ax, ax in al, 60h bt ax, 1 jc _success loop _attempt jmp _fail retn _success: sti popa xor ax, ax mov si, MA20 call _print retn _fail: jmp _badKarma ;See if 8042 is ready for command at port 64h or data at 60h. _commandwait: xor ax, ax in al, 64h bt ax, 1 jc _commandwait retn ;See if 8042 has data for us. _datawait xor ax, ax in al, 64h bt ax, 0 jnc _datawait retn _error: mov si, errno + 1 prnum: mov al, ah and al, 0fh cmp al, 0ah jb digit add al, 07h digit: add [si], al dec si mov cl, 04h shr ah, cl jnz prnum retn _print : lodsb or al, al jz _stop mov ah, 0eh mov bx, 0007h int 10h ;Jump to _print jmp _print _stop: retn _start: cli xor ax, ax mov ss, ax mov ds, ax mov sp, SPOFFSET sti ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;Lets save the registers that were set before us. push es push si push dx mov bp, sp ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;The booting message. mov si, logo ;The logo. call near _print ;call _print call _enableA20 ;Lets load the sector ID's of the kernel file. mov ax, SECTORSSEGMENT mov es, ax mov bx, SECTORSOFFSET mov ah, 02h ;Service number. mov al, 01h ;Number of sectors to read. mov ch, 00h ;Track number. mov cl, 02h ;Starting sector number. mov dh, 00h ;Head number. int 13h jc _handleErrors mov si, KSR call near _print ;Lets load the kernel. mov si, KCR call near _print ;Load the sector count. mov cx, [_seclow] mov si, SECTORSOFFSET mov ax, KERNELSEGMENT mov es, ax mov bx, KERNELOFFSET ; mov bx, KERNELOFFSET1 _loadKernel: push cx mov ah, 02h mov al, 01h mov cx, [si] mov dh, [si + 02h] int 13h jc _handleErrors pop cx add si, 03h add bx, 0200h push bx push si mov si, shit call near _print pop si pop bx loop _loadKernel pop dx pop si pop es mov ax, KERNELSEGMENT mov ds, ax ; db 0eah, 10h, 00h, 0ffh, 0ffh ;_humps: db 0eah, 00h, 00h, 00h, 10h ; db 0eah, 00h, 01h, 00h, 10h ; db 0eah, 00h, 00h, 00h, 10h _handleErrors: ; push si call near _error mov si, rderr call near _print mov si, errno call near _print ; pop si ;We should not reach this area, if we do then print the message and halt. _badKarma: mov si, MHLT call near _print _hold: hlt jmp _hold ;More Data. ;Total number of sectors to be read from the following sectors. ;This value should be orgin at 1 to max. _seclow dw 0002h