From dbe9918dc6c48068d0345592005f5599cdad9e8a Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Sat, 21 Jan 2017 00:14:05 +0000 Subject: [PATCH] Return capacity and bytes per sector of bios disks This patch makes bd_querymedia return valid Capacity and SectorSize values. Bios disks detection code saves the values to extended BiosDiskData structure, bd_querymedia copies them to DISKMEDIAINFO. git-svn-id: svn://kolibrios.org@6843 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/blkdev/bd_drv.inc | 28 +++++++++++++++++++++------- kernel/trunk/data32.inc | 2 +- kernel/trunk/detect/biosdisk.inc | 12 +++++++++++- kernel/trunk/detect/sear_par.inc | 3 ++- kernel/trunk/kernel.asm | 1 + 5 files changed, 36 insertions(+), 10 deletions(-) diff --git a/kernel/trunk/blkdev/bd_drv.inc b/kernel/trunk/blkdev/bd_drv.inc index a07057178b..1e05803291 100644 --- a/kernel/trunk/blkdev/bd_drv.inc +++ b/kernel/trunk/blkdev/bd_drv.inc @@ -31,6 +31,14 @@ int13_regs_in rb sizeof.v86_regs int13_regs_out rb sizeof.v86_regs cache_chain_size db ? endg + +struct BiosDiskData + DriveNumber db ? + IRQ db ? + ATADEVbit dw ? + SectorSize dd ? + Capacity dq ? +ends ;----------------------------------------------------------------- proc bd_read_interface stdcall uses edi, \ userdata, buffer, startsector:qword, numsectors @@ -152,13 +160,18 @@ endl ret endp ;----------------------------------------------------------------- -; This is a stub. proc bd_querymedia stdcall, hd_data, mediainfo - mov eax, [mediainfo] - mov [eax+DISKMEDIAINFO.Flags], 0 - mov [eax+DISKMEDIAINFO.SectorSize], 512 - or dword [eax+DISKMEDIAINFO.Capacity], 0xFFFFFFFF - or dword [eax+DISKMEDIAINFO.Capacity+4], 0xFFFFFFFF + mov edx, [mediainfo] + mov eax, [hd_data] + lea eax, [(eax-80h)*4] + lea eax, [BiosDisksData+eax*4] + mov [edx+DISKMEDIAINFO.Flags], 0 + mov ecx, [eax+BiosDiskData.SectorSize] + mov [edx+DISKMEDIAINFO.SectorSize], ecx + mov ecx, dword [eax+BiosDiskData.Capacity+0] + mov eax, dword [eax+BiosDiskData.Capacity+4] + mov dword [edx+DISKMEDIAINFO.Capacity+0], ecx + mov dword [edx+DISKMEDIAINFO.Capacity+4], eax xor eax, eax ret endp @@ -253,7 +266,8 @@ int13_call: rep stosd mov byte [ebx+v86_regs.eax+1], dl mov eax, [hdpos] - lea eax, [BiosDisksData+(eax-80h)*4] + lea eax, [(eax-80h)*4] + lea eax, [BiosDisksData+eax*4] mov dl, [eax] mov byte [ebx+v86_regs.edx], dl movzx edx, byte [eax+1] diff --git a/kernel/trunk/data32.inc b/kernel/trunk/data32.inc index 1929ece7a0..eb02dc6071 100644 --- a/kernel/trunk/data32.inc +++ b/kernel/trunk/data32.inc @@ -454,7 +454,7 @@ lba_read_enabled dd ? ; 0 = disabled , 1 = enabled pci_access_enabled dd ? ; 0 = disabled , 1 = enabled NumBiosDisks dd ? -BiosDisksData rb 200h +BiosDisksData rb 200h ; struct BiosDiskData BiosDiskCaches rb 80h*(cache_ide1-cache_ide0) BiosDiskPartitions rd 80h diff --git a/kernel/trunk/detect/biosdisk.inc b/kernel/trunk/detect/biosdisk.inc index 0176c125fd..8005f698bb 100644 --- a/kernel/trunk/detect/biosdisk.inc +++ b/kernel/trunk/detect/biosdisk.inc @@ -11,6 +11,7 @@ $Revision$ ; Detect all BIOS hard drives. ; diamond, 2008 ; Do not include USB mass storages. CleverMouse, 2013 +; Read the number of sectors, bytes per sector. dunkaist, 2017 xor cx, cx mov es, cx @@ -65,6 +66,7 @@ bdds: mov al, dl stosb push ds + push si lds si, [es:si+1Ah] mov al, [si+6] and al, 0xF @@ -82,8 +84,9 @@ bdds: ; mov ax, -1 @@: stosw + pop si pop ds - jmp bddc2 + jmp bddc3 .noide: cmp word [es:si], 42h jb .nousb @@ -103,6 +106,13 @@ bdds: ; stosb ; mov ax, -1 ; stosw +bddc3: + movzx eax, word[es:si+24] + stosd + mov eax, [es:si+16] + stosd + mov eax, [es:si+20] + stosd bddc2: cmp cl, [es:0x475] jae bdde diff --git a/kernel/trunk/detect/sear_par.inc b/kernel/trunk/detect/sear_par.inc index da4244de8c..1c896a27bd 100644 --- a/kernel/trunk/detect/sear_par.inc +++ b/kernel/trunk/detect/sear_par.inc @@ -216,7 +216,8 @@ search_partitions: push 'bd' .bdloop: ; 3b. Get the drive number for using in /bd* name. - movzx eax, byte [BiosDisksData+esi*4] + lea eax, [esi*4] + movzx eax, [BiosDisksData+eax*4+BiosDiskData.DriveNumber] sub al, 80h ; 3c. Convert eax to decimal and store starting with [esp+3]. ; First 2 bytes in [esp] are "bd". diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index b4ca4f0850..7a4b22a1da 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -451,6 +451,7 @@ high_code: movzx ecx, byte [esi-1] mov [NumBiosDisks], ecx mov edi, BiosDisksData + shl ecx, 2 rep movsd ; -------- Fast System Call init ----------