;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;; Miguel's FoolOS Helper Functions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ;disk_load_16 ; [bits 16] STR_ERROR: db "Disk Read Error",0 STR_SPACE db " ",0 STR_OK: db "Kernel Loaded",0 bpbSectorsPerTrack: dw 18 bpbHeadsPerCylinder: dw 2 LBA: dw 10 ; current lba disk_load_16: pusha mov bx,0x1000 ;target es:bx mov es,bx mov bx,0 next_sectors: pusha mov bx, STR_SPACE call print_string ;show es - target mov bx,es mov al,bh call print_hex_byte mov al,bl call print_hex_byte mov bx, STR_SPACE call print_string ;load and show next LBA numer mov ax,[LBA] mov al,ah call print_hex_byte mov ax,[LBA] call print_hex_byte mov bx, STR_SPACE call print_string popa mov ax,[LBA] ;calculate chs call lba_to_chs ;show chs sector/ head / cylinder mov al,cl call print_hex_byte mov al,dh call print_hex_byte mov al,ch call print_hex_byte call print_nextline ; and now READ it! mov al,16 ;number of sectors to read mov dl,[BOOT_DRIVE] mov ah,0x02 ;BIOS read sector func int 0x13 ;bios interrupt jc disk_read_error disk_read_error_continue: mov bx,es add bx,0x0200 cmp bx,0x9e00 je disk_load_finish mov es,bx mov bx,0 mov ax,[LBA] add ax,16 mov [LBA],ax jmp next_sectors disk_read_error: pusha mov bx, STR_ERROR call print_string call print_nextline popa jmp disk_read_error_continue disk_load_finish: mov bx, STR_OK call print_string call print_nextline popa ret ;lba to chs translation: ; input : ax - lba ; output: cl - sector ; dh - head ; ch - cylinder / track lba_to_chs: xor dx, dx ; prepare dx:ax for operation div WORD [bpbSectorsPerTrack] ; divide by sectors per track inc dl ; add 1 (obsolute sector formula) mov cl, dl xor dx, dx ; prepare dx:ax for operation div WORD [bpbHeadsPerCylinder] ; mod by number of heads (Absolue head formula) mov dh,dl ; everything else was already done from the first formula mov ch, al ; not much else to do :) ret