flat assembler
Message board for the users of flat assembler.
![]() Goto page 1, 2 Next |
Author |
|
Dex4u 26 May 2008, 19:11
NOTE: THE BELOW CODE WILL OVER WRITE YOUR MBR, so do not run with below settings.
To read/write to hdd is very easy, but it's the fat that will take more time, to get right. Code: ; Reading the harddisk using ports!; +-------------------------------+ by qark;;; This took me months to get working but I finally managed it.;; This code only works for the 286+ so you must detect for 8088's somewhere; in your code.;; Technical Information on the ports:; Port Read/Write Misc; ------ ------------ -------------------------------------------------; 1f0 r/w data register, the bytes are written/read here; 1f1 r error register (look these values up yourself); 1f2 r/w sector count, how many sectors to read/write; 1f3 r/w sector number, the actual sector wanted; 1f4 r/w cylinder low, cylinders is 0-1024; 1f5 r/w cylinder high, this makes up the rest of the 1024; 1f6 r/w drive/head; bit 7 = 1; bit 6 = 0; bit 5 = 1; bit 4 = 0 drive 0 select; = 1 drive 1 select; bit 3-0 head select bits; 1f7 r status register; bit 7 = 1 controller is executing a command; bit 6 = 1 drive is ready; bit 5 = 1 write fault; bit 4 = 1 seek complete; bit 3 = 1 sector buffer requires servicing; bit 2 = 1 disk data read corrected; bit 1 = 1 index - set to 1 each revolution; bit 0 = 1 previous command ended in an error; 1f7 w command register; commands:; 50h format track; 20h read sectors with retry; 21h read sectors without retry; 22h read long with retry; 23h read long without retry; 30h write sectors with retry; 31h write sectors without retry; 32h write long with retry; 33h write long without retry;; Most of these should work on even non-IDE hard disks.; This code is for reading, the code for writing is the next article. mov dx,1f6h ;Drive and head port mov al,0a0h ;Drive 0, head 0 out dx,al mov dx,1f2h ;Sector count port mov al,1 ;Read one sector out dx,al mov dx,1f3h ;Sector number port mov al,1 ;Read sector one out dx,al mov dx,1f4h ;Cylinder low port mov al,0 ;Cylinder 0 out dx,al mov dx,1f5h ;Cylinder high port mov al,0 ;The rest of the cylinder 0 out dx,al mov dx,1f7h ;Command port mov al,20h ;Read with retry. out dx,alstill_going: in al,dx test al,8 ;This means the sector buffer requires ;servicing. jz still_going ;Don't continue until the sector buffer ;is ready. mov cx,512/2 ;One sector /2 mov di,offset buffer mov dx,1f0h ;Data port - data comes in and out of here. rep insw; ------ mov ax,201h ;Read using int13h then compare buffers. mov dx,80h mov cx,1 mov bx,offset buffer2 int 13h mov cx,512 mov si,offset buffer mov di,offset buffer2 repe cmpsb jne failure mov ah,9 mov dx,offset readmsg int 21h jmp good_exitfailure: mov ah,9 mov dx,offset failmsg int 21hgood_exit: mov ax,4c00h ;Exit the program int 21h readmsg db 'The buffers match. Hard disk read using ports.$' failmsg db 'The buffers do not match.$'buffer db 512 dup ('V')buffer2 db 512 dup ('L');; Writing to the hard disk using the ports! by qark; +---------------------------------------+;; The only differences between reading and writing using the ports is; that 30h is sent to the command register, and instead of INSW you; OUTSW. ; mov dx,1f6h ;Drive and head port mov al,0a0h ;Drive 0, head 0 out dx,al mov dx,1f2h ;Sector count port mov al,1 ;Write one sector out dx,al mov dx,1f3h ;Sector number port mov al,1 ;Wrote to sector one out dx,al mov dx,1f4h ;Cylinder low port mov al,0 ;Cylinder 0 out dx,al mov dx,1f5h ;Cylinder high port mov al,0 ;The rest of the cylinder 0 out dx,al mov dx,1f7h ;Command port mov al,30h ;Write with retry. out dx,aloogle: in al,dx test al,8 ;Wait for sector buffer ready. jz oogle mov cx,512/2 ;One sector /2 mov si,offset buffer mov dx,1f0h ;Data port - data comes in and out of here. rep outsw ;Send it.; ------------ mov ax,201h ;We'll read in sector 1 using mov bx,offset buffer2 ;int13h and see if we are successful. mov cx,1 mov dx,80h int 13h mov cx,512 mov si,offset buffer mov di,offset buffer2 repe cmpsb ;Compare the buffers. jne failure mov ah,9 mov dx,offset write_msg int 21h jmp w_exitfailure: mov ah,9 mov dx,offset fail int 21hw_exit: mov ax,4c00h ;Exit the program int 21h write_msg db 'Sector one written to using the ports, OH NO! there goes XP.$' fail db 'Writing using ports failed.$'buffer db 512 dup ('A')buffer2 db 512 dup ('D') NOTE: THE ABOVE CODE WILL OVER WRITE YOUR MBR, so do not run with above settings. |
|||
![]() |
|
nihilist:P 26 May 2008, 19:24
Thank you very much... one more question:
Does that use PIO, right? What is today the most common way? Is DMA out??? |
|||
![]() |
|
nihilist:P 26 May 2008, 19:29
That is what I found there...
(Windows offers the option to enable the "good" DMA-mode.) After Reading this: http://www.osdev.org/wiki/DMA Quote:
Is that the same DMA??? rofl - nice job then INTEL |
|||
![]() |
|
Dex4u 26 May 2008, 20:20
Also read this will help http://www.osdev.org/wiki/ATA_PIO_Mode
|
|||
![]() |
|
StarKnightD 13 Sep 2008, 07:30
Hi,
I'm looking to code a HDD scanning program that works at boot time to determine which sectors are faulty.. I would like to be able to recover this information and black list the sectors in question. as long as I don't defrag the drive, I don't see how I need anything except a folder whose "files" are the damaged sectors. That aside, my first priority is actually using the BIOS or IO ports to access the drive, but I don't know how the "geometry" works as far as the BIOS is concerned, and I'm not sure about IO ports since, technically, it's a SATA drive. Would someone point me in the right direction as to programming this thing? first and foremost, I'm looking to diagnose the hard drives I have.. I finally bought a 500gb and the thing went bad.. nearly a year later I buy a second 500gb to replace it and it goes bad within days of the 30-day warranty running out. I have more storage capacity in these 2 things than I have in my other drives combined and I'm certainly not in the mood to buy another one (even if I could). The following text was rendered by Windows XP64 from within whatever progam pops open when an "nfo" file is opened (don't remember right now).. [Hardware Resources] [Conflicts/Sharing] Resource Device I/O Port 0x00000000-0x000003AF PCI bus I/O Port 0x00000000-0x000003AF Direct memory access controller I/O Port 0x000003C0-0x000003DF PCI standard PCI-to-PCI bridge I/O Port 0x000003C0-0x000003DF Radeon X1600 Series IRQ 20 Realtek AC'97 Audio IRQ 20 NVIDIA nForce4 Serial ATA Controller IRQ 20 NVIDIA Network Bus Enumerator I/O Port 0x00009000-0x0000FFFF PCI bus I/O Port 0x00009000-0x0000FFFF PCI standard PCI-to-PCI bridge Memory Address 0xD0000000-0xFEBFFFFF PCI bus Memory Address 0xD0000000-0xFEBFFFFF PCI standard PCI-to-PCI bridge Memory Address 0xD0000000-0xFEBFFFFF Radeon X1600 Series IRQ 19 VIA Rev 5 or later USB Universal Host Controller IRQ 19 VIA OHCI Compliant IEEE 1394 Host Controller Memory Address 0xA0000-0xBFFFF PCI bus Memory Address 0xA0000-0xBFFFF PCI standard PCI-to-PCI bridge Memory Address 0xA0000-0xBFFFF Radeon X1600 Series I/O Port 0x000003B0-0x000003DF PCI bus I/O Port 0x000003B0-0x000003DF PCI standard PCI-to-PCI bridge I/O Port 0x000003B0-0x000003DF Radeon X1600 Series [DMA] Resource Device Status Channel 4 Direct memory access controller OK Channel 2 Standard floppy disk controller OK [Forced Hardware] Device PNP Device ID [I/O] Resource Device Status 0x00000000-0x000003AF PCI bus OK 0x00000000-0x000003AF Direct memory access controller OK 0x000003B0-0x000003DF PCI bus OK 0x000003B0-0x000003DF PCI standard PCI-to-PCI bridge OK 0x000003B0-0x000003DF Radeon X1600 Series OK 0x000003E0-0x00000CF7 PCI bus OK 0x00009000-0x0000FFFF PCI bus OK 0x00009000-0x0000FFFF PCI standard PCI-to-PCI bridge OK 0x0000FF00-0x0000FF1F NVIDIA nForce PCI System Management OK 0x00004C00-0x00004C3F NVIDIA nForce PCI System Management OK 0x00004C40-0x00004C7F NVIDIA nForce PCI System Management OK 0x0000EA00-0x0000EAFF Realtek AC'97 Audio OK 0x0000EE00-0x0000EEFF Realtek AC'97 Audio OK 0x0000FB00-0x0000FB0F NVIDIA nForce4 Parallel ATA Controller OK 0x000001F0-0x000001F7 NVIDIA nForce4 Parallel ATA Controller OK 0x000003F6-0x000003F6 NVIDIA nForce4 Parallel ATA Controller OK 0x00000170-0x00000177 NVIDIA nForce4 Parallel ATA Controller OK 0x00000376-0x00000376 NVIDIA nForce4 Parallel ATA Controller OK 0x000009F0-0x000009F7 NVIDIA nForce4 Serial ATA Controller OK 0x00000BF0-0x00000BF3 NVIDIA nForce4 Serial ATA Controller OK 0x00000970-0x00000977 NVIDIA nForce4 Serial ATA Controller OK 0x00000B70-0x00000B73 NVIDIA nForce4 Serial ATA Controller OK 0x0000F600-0x0000F60F NVIDIA nForce4 Serial ATA Controller OK 0x000009E0-0x000009E7 NVIDIA nForce4 Serial ATA Controller OK 0x00000BE0-0x00000BE3 NVIDIA nForce4 Serial ATA Controller OK 0x00000960-0x00000967 NVIDIA nForce4 Serial ATA Controller OK 0x00000B60-0x00000B63 NVIDIA nForce4 Serial ATA Controller OK 0x0000F100-0x0000F10F NVIDIA nForce4 Serial ATA Controller OK 0x0000DF00-0x0000DF1F VIA Rev 5 or later USB Universal Host Controller OK 0x0000DE00-0x0000DE1F VIA Rev 5 or later USB Universal Host Controller OK 0x0000DD00-0x0000DD7F VIA OHCI Compliant IEEE 1394 Host Controller OK 0x0000F000-0x0000F007 NVIDIA Network Bus Enumerator OK 0x0000C000-0x0000CFFF PCI standard PCI-to-PCI bridge OK 0x0000B000-0x0000BFFF PCI standard PCI-to-PCI bridge OK 0x0000A000-0x0000AFFF PCI standard PCI-to-PCI bridge OK 0x000003C0-0x000003DF PCI standard PCI-to-PCI bridge OK 0x000003C0-0x000003DF Radeon X1600 Series OK 0x00009E00-0x00009EFF Radeon X1600 Series OK 0x00004000-0x0000407F Motherboard resources OK 0x00004080-0x000040FF Motherboard resources OK 0x00004400-0x0000447F Motherboard resources OK 0x00004480-0x000044FF Motherboard resources OK 0x00004800-0x0000487F Motherboard resources OK 0x00004880-0x000048FF Motherboard resources OK 0x00000010-0x0000001F Motherboard resources OK 0x00000022-0x0000003F Motherboard resources OK 0x00000044-0x0000005F Motherboard resources OK 0x00000062-0x00000063 Motherboard resources OK 0x00000065-0x0000006F Motherboard resources OK 0x00000074-0x0000007F Motherboard resources OK 0x00000091-0x00000093 Motherboard resources OK 0x000000A2-0x000000BF Motherboard resources OK 0x000000E0-0x000000EF Motherboard resources OK 0x00000B78-0x00000B7B Motherboard resources OK 0x00000F78-0x00000F7B Motherboard resources OK 0x00000A78-0x00000A7B Motherboard resources OK 0x00000E78-0x00000E7B Motherboard resources OK 0x00000BBC-0x00000BBF Motherboard resources OK 0x00000FBC-0x00000FBF Motherboard resources OK 0x000004D0-0x000004D1 Motherboard resources OK 0x00000290-0x0000030F Motherboard resources OK 0x00000020-0x00000021 Programmable interrupt controller OK 0x000000A0-0x000000A1 Programmable interrupt controller OK 0x00000080-0x00000090 Direct memory access controller OK 0x00000094-0x0000009F Direct memory access controller OK 0x000000C0-0x000000DF Direct memory access controller OK 0x00000040-0x00000043 System timer OK 0x00000070-0x00000073 System CMOS/real time clock OK 0x00000061-0x00000061 System speaker OK 0x000000F0-0x000000FF Numeric data processor OK 0x000003F0-0x000003F5 Standard floppy disk controller OK 0x000003F7-0x000003F7 Standard floppy disk controller OK 0x000003F8-0x000003FF Communications Port (COM1) OK 0x000002F8-0x000002FF Communications Port (COM2) OK 0x00000378-0x0000037F Printer Port (LPT1) OK 0x00000778-0x0000077B Printer Port (LPT1) OK 0x00000060-0x00000060 Standard 101/102-Key or Microsoft Natural PS/2 Keyboard OK 0x00000064-0x00000064 Standard 101/102-Key or Microsoft Natural PS/2 Keyboard OK [IRQs] Resource Device Status IRQ 9 Microsoft ACPI-Compliant System OK IRQ 12 NVIDIA nForce PCI System Management OK IRQ 22 Standard OpenHCD USB Host Controller OK IRQ 23 Standard Enhanced PCI to USB Host Controller OK IRQ 20 Realtek AC'97 Audio OK IRQ 20 NVIDIA nForce4 Serial ATA Controller OK IRQ 20 NVIDIA Network Bus Enumerator OK IRQ 14 NVIDIA nForce4 Parallel ATA Controller OK IRQ 15 NVIDIA nForce4 Parallel ATA Controller OK IRQ 21 NVIDIA nForce4 Serial ATA Controller OK IRQ 19 VIA Rev 5 or later USB Universal Host Controller OK IRQ 19 VIA OHCI Compliant IEEE 1394 Host Controller OK IRQ 16 VIA Rev 5 or later USB Universal Host Controller OK IRQ 17 VIA USB Enhanced Host Controller OK IRQ 18 Radeon X1600 Series OK IRQ 0 System timer OK IRQ 8 System CMOS/real time clock OK IRQ 13 Numeric data processor OK IRQ 6 Standard floppy disk controller OK IRQ 4 Communications Port (COM1) OK IRQ 3 Communications Port (COM2) OK IRQ 1 Standard 101/102-Key or Microsoft Natural PS/2 Keyboard OK [Memory] Resource Device Status 0xA0000-0xBFFFF PCI bus OK 0xA0000-0xBFFFF PCI standard PCI-to-PCI bridge OK 0xA0000-0xBFFFF Radeon X1600 Series OK 0xD0000000-0xFEBFFFFF PCI bus OK 0xD0000000-0xFEBFFFFF PCI standard PCI-to-PCI bridge OK 0xD0000000-0xFEBFFFFF Radeon X1600 Series OK 0xFEBFF000-0xFEBFFFFF Standard OpenHCD USB Host Controller OK 0xFEBFE000-0xFEBFE0FF Standard Enhanced PCI to USB Host Controller OK 0xFEBFD000-0xFEBFDFFF Realtek AC'97 Audio OK 0xFEBFB000-0xFEBFBFFF NVIDIA nForce4 Serial ATA Controller OK 0xFEBFA000-0xFEBFAFFF NVIDIA nForce4 Serial ATA Controller OK 0xFE9FF000-0xFE9FF0FF VIA USB Enhanced Host Controller OK 0xFE9FE000-0xFE9FE7FF VIA OHCI Compliant IEEE 1394 Host Controller OK 0xFEBF9000-0xFEBF9FFF NVIDIA Network Bus Enumerator OK 0xFE800000-0xFE8FFFFF PCI standard PCI-to-PCI bridge OK 0xFE700000-0xFE7FFFFF PCI standard PCI-to-PCI bridge OK 0xFE600000-0xFE6FFFFF PCI standard PCI-to-PCI bridge OK 0xFE500000-0xFE5FFFFF PCI standard PCI-to-PCI bridge OK 0xFE400000-0xFE4FFFFF PCI standard PCI-to-PCI bridge OK 0xFE300000-0xFE3FFFFF PCI standard PCI-to-PCI bridge OK 0xFE200000-0xFE2FFFFF PCI standard PCI-to-PCI bridge OK 0xFE2F0000-0xFE2FFFFF Radeon X1600 Series OK 0xFE2E0000-0xFE2EFFFF Radeon X1600 Series Secondary OK 0xE0000000-0xEFFFFFFF Motherboard resources OK 0xF0000-0xF3FFF System board OK 0xF4000-0xF7FFF System board OK 0xF8000-0xFBFFF System board OK 0xFC000-0xFFFFF System board OK 0x3FFF0000-0x3FFFFFFF System board OK 0xFFFF0000-0xFFFFFFFF System board OK 0x0000-0x9FFFF System board OK 0x100000-0x3FFEFFFF System board OK 0xFEC00000-0xFEC00FFF System board OK 0xFEE00000-0xFEEFFFFF System board OK 0xFEFFF000-0xFEFFFFFF System board OK 0xFFF80000-0xFFF80FFF System board OK 0xFFF90000-0xFFFBFFFF System board OK 0xFFFED000-0xFFFEFFFF System board OK |
|||
![]() |
|
sinsi 13 Sep 2008, 07:45
Just use chkdsk
|
|||
![]() |
|
revolution 13 Sep 2008, 08:20
Yes, chkdsk, or even spinrite for a more thorough analysis.
But if you want to "roll your own" then I recommend you use the BIOS INT 13h interface. It is simple and easy to use without the concern about ports and I/O controllers etc. [edit]changed to INT 13h[/edit] Last edited by revolution on 13 Sep 2008, 09:52; edited 1 time in total |
|||
![]() |
|
sinsi 13 Sep 2008, 09:42
revolution wrote: use the BIOS INT 10h interface. INT 13h maybe? ![]() |
|||
![]() |
|
revolution 13 Sep 2008, 09:51
sinsi wrote:
![]() |
|||
![]() |
|
neville 13 Sep 2008, 09:57
Dex4u wrote:
Quote: buffer2 db 512 dup ("D") What sort of weird code is this? We don't DUP around here laddie, we TIMES ![]() OK, so the (MASM) code will work for legacy CHS access up to 1024cyl x 63s x 16h x 512b = 500Mb or so. But nihilist's disks are 500Gb. Have you got any code for absolute 32-bit sector / "LBA" access ? _________________ FAMOS - the first memory operating system |
|||
![]() |
|
StarKnightD 13 Sep 2008, 10:35
Quote:
I think you're referring to me.. and no, I'm trying to find info on absolute addressing.. Quote:
doesn't work, already tried it.. one drive has mechanical problems, the other one doesn't wanna be helped by chkdsk.. I ran chkdsk and it still keeps my OS from booting. as far as the one with mechanical problems go, I'd like to isolate the sectors which cause it.. I think one of the heads are damaged. |
|||
![]() |
|
edfed 13 Sep 2008, 11:16
Quote: got any code for absolute 32-bit sector / "LBA" access ? there is no 32 bits LBA addresses. only LBA 28 and LBA 48 FAT32 is FAT28 first, following the docs, you should select the drive. master? slave? read it's feature, driveID 0Eh after, set it's mode. but... just take a look at this old news are good also. with LBA28, you can theorically access up to 2^28*2^9 = 2^37 bytes. 128 Gigabytes. Last edited by edfed on 11 Sep 2009, 22:55; edited 2 times in total |
|||
![]() |
|
LocoDelAssembly 13 Sep 2008, 11:20
IBM/MS INT 13 Extensions - EXTENDED READ (Read the others of the family too)
According to what SpinRite's author says it is advisable to disable S.M.A.R.T. before trying to recover data on damaged sectors because otherwise the HDD logic will replace them with spare sectors making the damaged one unnacessible for ever (not counting special equipment that could exist to do raw reading of the surface of course). Those HDDs were Western Digital? Quote:
fasm supports dup and it is faster than times but yet dup is very slow ![]() Code: ; Tests on AMD Athlon64 2.0 GHz using FASMW 1.67.27 ; 0.1 seconds rb 1024*1024*10 - 1 db 0 ; 1.0-1.1 seconds times 1024*1024*10 db 0 ; 0.6 seconds db 1024*1024*10 dup (0) |
|||
![]() |
|
edfed 13 Sep 2008, 11:33
Quote: fasm supports dup and it is faster than times but yet dup is very slow no comment. apparentlly, fasm is optimised for RISC assembly. PIII mobile @ 800MHz ; 0.4 second rb 1024*1024*10 - 1 db 0 ; 3.2 seconds times 1024*1024*10 db 0 ; 2.4 seconds db 1024*1024*10 dup (0) |
|||
![]() |
|
StarKnightD 13 Sep 2008, 12:53
Quote:
one drive is a Samsung HD501LJ the other one is Seagate ST3500630AS Quote:
I will! Thanks! |
|||
![]() |
|
Dex4u 13 Sep 2008, 15:08
neville wrote: Dex4u wrote: As well as what's been posted above, i did not write it, if you read the code it say Quote:
|
|||
![]() |
|
neville 13 Sep 2008, 20:08
Dex, no explanation required, it was just my poor attempt at some humour
StarKnightD, sorry didn't see you ![]() edfed, I agree, but also there are 32-bit absolute sectors. For example, in every HD partition table. And of course in INT13h EDD BIOS extensions. LocoDelAssembly, thanx, I wonder when FASM started supporting dup? I've never used FASMW, and at least up to DOS version 1.51 (2004) it's not supported and after converting all dup's to the times syntax I've never tried dup again. I just checked and FASM 1.66 for DOS does support dup. revolution, getting back to nihilist's first question, is it possible to use INT 13h in long mode after all? (I must get myself a 64-bit machine one day so I can find out for myself ![]() _________________ FAMOS - the first memory operating system |
|||
![]() |
|
revolution 13 Sep 2008, 23:36
neville wrote: revolution, getting back to nihilist's first question, is it possible to use INT 13h in long mode after all? Short answer: Yes Long answer: Yes, but you will need a 16bit emulator environment. Not so simple to implement properly. |
|||
![]() |
|
neville 14 Sep 2008, 04:40
So how can large disks be accessed in long mode, using ports and controllers?
![]() _________________ FAMOS - the first memory operating system |
|||
![]() |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.