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) --- Makefile | 2 +- bochsrc | 6 +-- boot/disk_load_16.asm | 102 +++++++++++++++++++++++++++++++++++++++++++---- boot/print_string_16.asm | 46 +++++++++++++++++++-- boot/stage2.asm | 32 +++++++++------ boot/vesa_setup_16.asm | 11 +++++ boot0/disk_load_16.asm | 44 ++++++++++++++++---- boot0/mbr.asm | 28 +++++++++++-- 8 files changed, 233 insertions(+), 38 deletions(-) diff --git a/Makefile b/Makefile index f12c36f..a039991 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ ############ some constants ############ -USB_STICK=/dev/sdg #take care! +USB_STICK=/dev/sdf #take care! #here our kernel will be loaded by the bootloader. KERNEL_START=0x10000 diff --git a/bochsrc b/bochsrc index 8d1af39..9588480 100644 --- a/bochsrc +++ b/bochsrc @@ -299,7 +299,7 @@ vga: extension=cirrus # The optional parameter 'write_protected' can be used to control the media # write protect switch. By default it is turned off. #======================================================================= -floppya: 1_44=FoolOS.img, status=inserted +#floppya: 1_44=FoolOS.img, status=inserted #floppya: image=../1.44, status=inserted #floppya: 1_44=/dev/fd0H1440, status=inserted #floppya: 1_2=../1_2, status=inserted @@ -377,7 +377,7 @@ floppya: 1_44=FoolOS.img, status=inserted # The biosdetect option has currently no effect on the bios # # Examples: -# ata0-master: type=disk, mode=flat, path=FoolOS.img, cylinders=10, heads=4, spt=18 + ata0-master: type=disk, mode=flat, path=FoolOS.img #, cylinders=10, heads=4, spt=18 # ata0-master: type=disk, mode=flat, path=disk.img # ata0-slave: type=disk, mode=flat, path=20M.sample, cylinders=615, heads=4, spt=17 # ata1-master: type=disk, mode=flat, path=30M.sample, cylinders=615, heads=6, spt=17 @@ -405,7 +405,7 @@ floppya: 1_44=FoolOS.img, status=inserted # boot: cdrom, floppy, disk #======================================================================= #boot: floppy -#boot: disk +boot: disk #boot: floppy #======================================================================= 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 diff --git a/boot0/disk_load_16.asm b/boot0/disk_load_16.asm index 55ad4aa..6762469 100644 --- a/boot0/disk_load_16.asm +++ b/boot0/disk_load_16.asm @@ -9,15 +9,15 @@ [bits 16] STR_LBA: - db "\nLBA Support Detected (no support yet)",0 + db "LBA Support Detected",0 -STR_CHS +STR_CHS: db "CHS Support Detected",0 -STR_ERROR +STR_ERROR: db "Disk Read Error",0 -STR_DONE +STR_DONE: db "Stage 2 Loaded",0 disk_load_16: @@ -31,14 +31,23 @@ disk_load_16: jnc disk_load_lba jmp disk_load_chs - disk_load_lba: mov bx, STR_LBA call print_string call print_nextline - jmp $ - jmp disk_load_finish + + mov dl,[BOOT_DRIVE] + xor ah,ah + mov ah,0x42 + + mov bx,0 + mov ds,bx + lea si,[lba_adr] + + int 0x13 + jnc disk_load_finish + jmp disk_load_error disk_load_chs: @@ -63,6 +72,12 @@ disk_load_chs: jnc disk_load_finish +disk_load_error: + + call print_nextline + mov bx, STR_ERROR + call print_string + call print_nextline jmp $ disk_load_finish: @@ -75,4 +90,17 @@ disk_load_finish: popa 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 0x7e00 + dw 0x7e00 ; target addr. offset + dw 0x0000 ; target addr. sector + + dd 1 ; first sector to read + dd 0 diff --git a/boot0/mbr.asm b/boot0/mbr.asm index d24bbfe..9f5a51d 100644 --- a/boot0/mbr.asm +++ b/boot0/mbr.asm @@ -11,11 +11,14 @@ jmp stage1 STR_1: - db "Starting Fool Loader Stage 1. v0.1",0 + db "Fool Loader Stage 1. v0.1",0 STR_2: db "Starting Stage 2",0 +STR_BOOT: + db "boot drive: ",0 + BOOT_DRIVE: db 0xff ; remember the bootdrive here @@ -24,23 +27,40 @@ BOOT_DRIVE: stage1: + ;remember BOOT_DRIVE (as was set by BIOS) + mov [BOOT_DRIVE],dl + ;first of allsetup the stack (Right under mbr) ;guaranteed ~30KB space mov bp,0x07bff mov sp,bp - - ;remember BOOT_DRIVE (as was set by BIOS) - mov [BOOT_DRIVE],dl + call print_clear + call print_nextline + + ;pr message mov bx, STR_1 call print_string call print_nextline + ;show bootdrive + mov bx, STR_BOOT + call print_string + + mov al,[BOOT_DRIVE] + call print_hex_byte + call print_nextline + + call disk_load_16 ; loads stage 2 + ;entering stage2 message mov bx, STR_2 call print_string call print_nextline + + call print_nextline + mov dl,[BOOT_DRIVE] jmp 0x7e00 ; jump to next sector where we put stage 2 ;fill partition table (4x16byte) with zeroes. -- cgit v1.2.3