diff options
| author | Michal Idziorek <m.i@gmx.at> | 2014-09-04 23:38:33 +0200 |
|---|---|---|
| committer | Michal Idziorek <m.i@gmx.at> | 2014-09-04 23:38:33 +0200 |
| commit | 467e19b262d435f1820539bc0c85ed4fa31b9687 (patch) | |
| tree | c3ee7690b089713614309857ecfc046d6a13d160 /boot/disk_load_16.asm | |
| parent | 487ecc1615ccc0368f1520c1146b2b43cdab6577 (diff) | |
Finally we have a 2 stage bootloader !
This one can load the ramdis up to 0xfffff :)
Diffstat (limited to 'boot/disk_load_16.asm')
| -rw-r--r-- | boot/disk_load_16.asm | 206 |
1 files changed, 101 insertions, 105 deletions
diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm index eae15a0..2a209fc 100644 --- a/boot/disk_load_16.asm +++ b/boot/disk_load_16.asm @@ -7,146 +7,142 @@ [bits 16] -DISK_LOAD: - db "D",0 -DISK_LOAD_ERROR - db "E",0 -Head: - db 0 -Track: - db 0 -Sector: - db 1 -LBA: - dw 0 ;; starts at zero! -Sectors: - dw 80 -Heads: +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 routune (load dh sectors from drive dl to es:bx) -;lba mode has 52 sectors hardcoded! disk_load_16: pusha - -;;; ; check if LBA is supported -;;; pusha -;;; mov ah,0x41 -;;; mov bx,0x55aa -;;; int 0x13 -;;; jnc disk_load_lba -;;; popa - disk_load_next: + 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 - call ESBX + mov al,dh + call print_hex_byte - ; load using CHS -;; mov al,80 ;read dh sectors (amount) -;; mov cx,[LBA] -;; cmp cx,0 -;; jne disk_read_normal -;; mov al,79 ;read dh sectors (amount) -;; disk_read_normal + mov al,ch + call print_hex_byte - mov al,1 + call print_nextline - mov cl,[Sector] ;sector - mov ch,[Track] ;cyl + ; and now READ it! + mov al,16 ;number of sectors to read mov dl,[BOOT_DRIVE] - mov dh,[Head] ;head mov ah,0x02 ;BIOS read sector func int 0x13 ;bios interrupt - jnc disk_read_ok ;ready becaue of error :( + jc disk_read_error + disk_read_error_continue: - mov bx, DISK_LOAD_ERROR - call print_string - - jmp $ + mov bx,es + add bx,0x0200 + cmp bx,0x9e00 + je disk_load_finish - disk_read_ok: + mov es,bx + mov bx,0 mov ax,[LBA] + add ax,16 + mov [LBA],ax - cmp ax,880 - je disk_load_ready + jmp next_sectors - mov bx, DISK_LOAD + disk_read_error: + pusha + mov bx, STR_ERROR call print_string + call print_nextline + popa + jmp disk_read_error_continue - add ax,1 ;conver LBA to CHS - mov [LBA],ax +disk_load_finish: + + mov bx, STR_OK + call print_string + call print_nextline - call LBACHS + popa + ret - jmp disk_load_next - disk_load_ready: - jmp $ +;lba to chs translation: +; input : ax - lba +; output: cl - sector +; dh - head +; ch - cylinder / track - popa - ret - -ESBX: +lba_to_chs: - xor dx,dx - xor dx,dx - mov ax,[LBA] - mov bx,0x200 - mul bx - mov bx,ax - add dx,1 - shl dx,12 - mov es,dx - -ret - - - ; load using LBA - -;;;disk_load_lba: -;;; -;;; popa -;;; -;;; xor ah,ah -;;; mov ah,0x42 -;;; lea si,[lba_adr] -;;; int 0x13 -;;; jc skip_print -;;; mov bx, DISK_LOAD -;;; call print_string -;;; skip_print: -;;; -;;; popa -;;; ret -;;; -LBACHS: xor dx, dx ; prepare dx:ax for operation - div WORD [Sectors] ; divide by sectors per track + div WORD [bpbSectorsPerTrack] ; divide by sectors per track inc dl ; add 1 (obsolute sector formula) - mov BYTE [Sector], dl + mov cl, dl xor dx, dx ; prepare dx:ax for operation - div WORD [Heads] ; mod by number of heads (Absolue head formula) - mov BYTE [Head], dl ; everything else was already done from the first formula + div WORD [bpbHeadsPerCylinder] ; mod by number of heads (Absolue head formula) + mov dh,dl ; everything else was already done from the first formula - mov BYTE [Track], al ; not much else to do :) + mov ch, al ; not much else to do :) ret -lba_adr: - - dw 0x10 ; size of packet ( 16 byte) - - dw 53 ; number of sectors to read - - dw 0x0000 ; target addr. offset - dw 0x1000 ; target addr. sector - - dd 1 ; first sector to read - dd 0 ; |
