From b75c10c9d8c7405ba2f89724b485154d5201c404 Mon Sep 17 00:00:00 2001 From: Michal Idziorek Date: Fri, 5 Sep 2014 02:36:33 +0200 Subject: working on bootloaders (lba) --- boot/disk_load_16.asm | 102 +++++++++++++++++++++++++++++++++++++++++++---- boot/print_string_16.asm | 46 +++++++++++++++++++-- boot/stage2.asm | 32 +++++++++------ boot/vesa_setup_16.asm | 11 +++++ 4 files changed, 169 insertions(+), 22 deletions(-) (limited to 'boot') diff --git a/boot/disk_load_16.asm b/boot/disk_load_16.asm index 2a209fc..764b80d 100644 --- a/boot/disk_load_16.asm +++ b/boot/disk_load_16.asm @@ -27,14 +27,79 @@ LBA: disk_load_16: + ; check if LBA is supported + mov ah,0x41 + mov bx,0x55aa + int 0x13 + jnc disk_load_lba + jmp disk_load_chs + + +;####################### + +disk_load_lba: + pusha mov bx,0x1000 ;target es:bx mov es,bx mov bx,0 - next_sectors: + next_sectors_lba: + ;show es - target + pusha + mov bx,es + + mov al,bh + call print_hex_byte + + mov al,bl + call print_hex_byte + popa + ;-- + + mov [lba_addr_sector],es + mov ax,[LBA] + mov [lba_first_sector],ax + + mov dl,[BOOT_DRIVE] + + mov ah,0x42 + mov bx,0 + mov ds,bx + lea si,[lba_adr] + int 0x13 + jc disk_read_error + + 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_lba + +;####################### + + +disk_load_chs: + + pusha + + mov bx,0x1000 ;target es:bx + mov es,bx + mov bx,0 + + next_sectors_chs + + jmp skip_debug pusha mov bx, STR_SPACE @@ -82,7 +147,13 @@ disk_load_16: call print_nextline + skip_debug + + mov ax,[LBA] + + ;calculate chs + call lba_to_chs ; and now READ it! mov al,16 ;number of sectors to read mov dl,[BOOT_DRIVE] @@ -91,7 +162,6 @@ disk_load_16: int 0x13 ;bios interrupt jc disk_read_error - disk_read_error_continue: mov bx,es add bx,0x0200 @@ -105,15 +175,13 @@ disk_load_16: add ax,16 mov [LBA],ax - jmp next_sectors + jmp next_sectors_chs - disk_read_error: - pusha +disk_read_error: mov bx, STR_ERROR call print_string call print_nextline - popa - jmp disk_read_error_continue + jmp $ disk_load_finish: @@ -146,3 +214,23 @@ lba_to_chs: mov ch, al ; not much else to do :) ret +;; here we hold the lba addr +lba_adr: + + dw 0x10 ; size of packet ( 16 byte) + dw 16 ; number of sectors to read + + ; target is 0x10000 + + dw 0x0000 ; target addr. offset + +lba_addr_sector: + dw 0x1000 ; target addr. sector + +lba_first_sector: + dw 10 ; first sector to read + dw 0 + + dd 0 + + ; diff --git a/boot/print_string_16.asm b/boot/print_string_16.asm index 92b4ea0..b758725 100644 --- a/boot/print_string_16.asm +++ b/boot/print_string_16.asm @@ -1,5 +1,11 @@ [bits 16] +BLANK: + db 0x12 + +SPACE: + db " ",0 + ;print_string routine ([bx]) ;this routine will print a null terminated string at [bx] to the screen. print_string: @@ -27,19 +33,53 @@ print_string: popa ;pop all registers ret ;return to caller +print_clear: + +pusha + mov ah,0x6 ;func + mov al,0 ;scroll one line + mov bh,[BLANK] ;blank char + + mov ch,0 ;upper left corner + mov cl,0 + mov dh,20 ;lower right corner + mov dl,40 + int 0x10 + + mov ah,0x2 + mov bh,0 + mov dl,0 + mov dh,15 + int 0x10 +popa + print_nextline: pusha + mov ah,0x6 ;func + mov al,1 ;scroll one line + mov bh,[BLANK] ;blank char + + mov ch,0 ;upper left corner + mov cl,0 + mov dh,20 ;lower right corner + mov dl,40 + int 0x10 + + mov ah,0x3 - mov bh,0 + mov bh,0 int 0x10 + mov ah,0x2 - mov bh,0 - inc dh mov dl,0 int 0x10 + + mov bx,SPACE + call print_string + popa ret diff --git a/boot/stage2.asm b/boot/stage2.asm index 27f9832..de2497e 100644 --- a/boot/stage2.asm +++ b/boot/stage2.asm @@ -55,16 +55,13 @@ BOOT_DRIVE: STR_VERSION: db "Fool Loader Stage 2 v0.5",0 -VESA_CHECK1: - db "1",0 -VESA_CHECK2: - db "2",0 -VESA_CHECK3: - db "3",0 -CHECK_A20: - db "A",0 STR_LOAD db "Loading Kernel...",0 +STR_BOOT + db "Boot Drive: ",0 +MEMMAP_INFO: + db "Getting Memory Map from BIOS.",0 + ; ;;lets put our temporary GDT (Global Descriptor Table) here ;;kernel should move this away @@ -90,27 +87,38 @@ STR_LOAD boot_16: + mov [BOOT_DRIVE],dl ; pr info mov bx, STR_VERSION call print_string call print_nextline -; remember BOOT_DRIVE again - mov [BOOT_DRIVE],dl + mov bx, STR_BOOT + call print_string + mov al,dl + call print_hex_byte + call print_nextline -; Load the KERNEL Image + ;show bootdrive + + ; Load the KERNEL Image mov bx, STR_LOAD call print_string call print_nextline call disk_load_16 - + + ; memmap message + mov bx,MEMMAP_INFO + call print_string + call print_nextline ;get memory map from bios before we enter 32 bit protected mode mov ax,0 ; set target address in es:di (0:offset) mov es,ax mov di,MEMMAP_OFFSET call BiosGetMemoryMap ; this will also put the number of entries ; of the memory map at MEMMAP_SIZE_OFFSET + call VesaSetup call switch_to_pm diff --git a/boot/vesa_setup_16.asm b/boot/vesa_setup_16.asm index f21cbff..40ca0c1 100644 --- a/boot/vesa_setup_16.asm +++ b/boot/vesa_setup_16.asm @@ -1,3 +1,10 @@ +VESA_CHECK1: + db "VESA: get modes!",0 +VESA_CHECK2: + db "VESA: get info on target mode!",0 +VESA_CHECK3: + db "VESA: switching to target mode!",0 + VesaSetup: pusha @@ -11,6 +18,7 @@ VesaSetup: vesa_err: mov bx, VESA_CHECK1 call print_string + call print_nextline cmp ax,0x004f je vesa_ok jmp vesa_err @@ -28,11 +36,13 @@ VesaSetup: vesa_err2: mov bx, VESA_CHECK2 call print_string + call print_nextline cmp ax,0x004f je vesa_ok2 jmp vesa_err2 vesa_ok2: + ;VESA: finally switch to the mode of choice! mov ax,0x4f02 ;vesa function: Set Mode mov bx,VESA_MODE_SELECT @@ -42,6 +52,7 @@ VesaSetup: vesa_err3: mov bx, VESA_CHECK3 call print_string + call print_nextline jmp vesa_err3 vesa_ok3: popa -- cgit v1.2.3