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 | |
| parent | 487ecc1615ccc0368f1520c1146b2b43cdab6577 (diff) | |
Finally we have a 2 stage bootloader !
This one can load the ramdis up to 0xfffff :)
Diffstat (limited to 'boot')
| -rw-r--r-- | boot/disk_load_16.asm | 206 | ||||
| -rw-r--r-- | boot/print_string_16.asm | 47 | ||||
| -rw-r--r-- | boot/stage2.asm (renamed from boot/mbr.asm) | 93 |
3 files changed, 172 insertions, 174 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 ; diff --git a/boot/print_string_16.asm b/boot/print_string_16.asm index 5d8ad5c..92b4ea0 100644 --- a/boot/print_string_16.asm +++ b/boot/print_string_16.asm @@ -26,3 +26,50 @@ print_string: popa ;pop all registers ret ;return to caller + +print_nextline: + + pusha + + mov ah,0x3 + mov bh,0 + int 0x10 + + mov ah,0x2 + mov bh,0 + inc dh + mov dl,0 + int 0x10 + popa + ret + + +;print byte from al to screen + print_hex_byte: + + pusha + + mov [.temp],al + shr al,4 + cmp al,10 + sbb al,69h + das + + mov ah,0Eh + int 10h + + mov al,[.temp] + ror al,4 + shr al,4 + cmp al,10 + sbb al,69h + das + + mov ah,0Eh + int 10h + +popa + + ret + + .temp db 0 diff --git a/boot/mbr.asm b/boot/stage2.asm index a854615..27f9832 100644 --- a/boot/mbr.asm +++ b/boot/stage2.asm @@ -2,14 +2,6 @@ ; ; THE FOOL-BOOT-LOADER ; -; So we have just been loaded by the BIOS and are in 16-bits real mode! -; Now the following work will bee accomplished (chronologically): -; -; NOTE: this should not exceed 446 bytes -; (otherwise it does not work on my Acer Aspire) -; -; * BOOT_DRIVE set -; ; * X sectors of our kernel loaded at KERNEL_OFFSET from floppy ; ; * memory map made available at MEMMAP_OFFSET @@ -39,32 +31,30 @@ ;this is where the BIOS per definition will put the first ;512 bytes of data from the boot device ;The Boot record is identified by the last 2 magic bytes: 0xaa55 (?) -[org 0x7c00] +[org 0x7e00] ;;define some constants ;;where we will load our kernel into memory and some ;;other memory locations ; +KERNEL_DATA equ 10 ;sector on disk where the kernel starts KERNEL_SECTOR equ 0x1000 KERNEL_OFFSET equ 0x0000 -MEMMAP_SIZE_OFFSET equ 0x7c00+0x600 -MEMMAP_OFFSET equ 0x7c00+0x400 +MEMMAP_SIZE_OFFSET equ 0x7c00 +MEMMAP_OFFSET equ 0x7c01 VESA_MODES equ 0x8300 VESA_MODE_INFO equ 0x8400 VESA_MODE_SELECT equ 0x4114 - ; jmp boot_16 ;start boot process - db 'X' -jmp $ ;entry for other processors ;) - db 'X' -; + ;;SOME Global Data, mainly info/error strings BOOT_DRIVE: db 0xff STR_VERSION: - db "v0.5",0 + db "Fool Loader Stage 2 v0.5",0 + VESA_CHECK1: db "1",0 VESA_CHECK2: @@ -73,6 +63,8 @@ VESA_CHECK3: db "3",0 CHECK_A20: db "A",0 +STR_LOAD + db "Loading Kernel...",0 ; ;;lets put our temporary GDT (Global Descriptor Table) here ;;kernel should move this away @@ -95,63 +87,37 @@ CHECK_A20: ; ;;lets start [bits 16] -; -boot_16: +boot_16: - ;first of allsetup the stack (Right under mbr) - ;guaranteed ~30KB space - mov bp,0x07bff - mov sp,bp -; -; +; pr info mov bx, STR_VERSION call print_string -; -; ;remember BOOT_DRIVE (as was set by BIOS) + call print_nextline + +; remember BOOT_DRIVE again mov [BOOT_DRIVE],dl -; ;Load the IMAGE +; Load the KERNEL Image + mov bx, STR_LOAD + call print_string + call print_nextline call disk_load_16 -; -; ;get memory map from bios before we enter 32 bit protected mode + ;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 + ; of the memory map at MEMMAP_SIZE_OFFSET + call VesaSetup -;a20check: -; -; mov bx, CHECK_A20 -; call print_string -; -; call check_a20 -; cmp ax,0 -; je a20check ;hang if a20 is disabled! - -; ;VESA: also setup vesa stuff before entering 32 bit protected mode -; call VesaSetup -; -; ;finally lets enter Protected mode!!! call switch_to_pm ; ;;;;;;;;; BOOT 32-bit protected mode;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; [bits 32] boot_32_pm: -; - -; ;enable A20 -; ;http://www.brokenthorn.com/Resources/OSDev9.html -; ;Method 3.1: Enables A20 through keyboard controller -; ;Not all keyboard controllers support this -; ; does not work in virtual box (with VT-x accerleration?) - -; mov al, 0xdd ; command 0xdd: enable a20 -; mov al, 0xdf ; command 0xdf: disable a20 -; out 0x64, al ; send command to controller ;Fast A20 Gate: ;http://wiki.osdev.org/A20_Line @@ -161,18 +127,7 @@ boot_32_pm: out 0x92, al ; call kernel! - mov eax,0 ;booting processor - call 0x10000 ;KERNEL_SECTOR:KERNEL_OFFSET ;jump into our Kernel! -; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; - -;fill partition table (4x16byte) with zeroes. -;(otherwise my Acer Aspire will not boot) -;times 64 db 0x0 - -;so we get identified as MBR -times 510-($-$$) db 0x0 -;dw 0x0 -dw 0xaa55 + mov eax,0 ;tell the kernel + ; we are the booting processor + call 0x10000 ;jump into our Kernel! |
