logo
Tags down

shadow

Reading remapped hdd sectors


By : Dee
Date : August 01 2020, 03:00 AM
will be helpful for those in need The physical sectors on the HDD gets remapped if there is non-recoverable ECC error.
There is no need to examine the unused spare sectors, since they will be empty and the ones which are used are mapped instead of the original sector.
code :


Share : facebook icon twitter icon

Reading Hard Disk Sectors in C++ on Linux


By : user25724
Date : March 29 2020, 07:55 AM
Does that help The hard disk is just another file (not a "regular file" but a "device file", but still, a file). Open it the normal way...
code :
int fdes = open("/dev/sda1", O_RDONLY);
if (fdes < 0)
    err(1, "/dev/sda1");
... do more ...

Trouble Reading Sectors off of CD INT 13h AH=42H


By : typedef struct
Date : March 29 2020, 07:55 AM
seems to work fine The BIOS provides the number of drive it booted off in the DL register. Drive 00h is the first floppy drive, drive 01h is the second. Drive 80h is the first hard disk, and subsequent hard drives follow. When booting from a CD-ROM, and only when booting from a CD-ROM, the BIOS emulates the CD-ROM as if it were a hard disk. That's why you can use the INT 13h, AX=42 Extended Read BIOS call to read it. The drive number that BIOS assigns the emulated CD-ROM varies from system to system so you can't hard code it.

Reading more sectors than there are on a track with int 13h


By : Hendrouw Hahihahi
Date : March 29 2020, 07:55 AM
may help you . Modern BIOSes support the concept of multitrack1 reads and writes. If you read or write past the end of a track it will continue on with the following track. To be most compatible with the widest array of BIOSes (old and new) you may wish to consider not reading or writing across a track boundary.
With a drive geometry of 18 sector per track/2 heads/80 cylinders (3.5" 1.44MB floppy), the sector after CHS(0,0,18) is CHS(0,1,1). After you reach sector at CHS(0,1,18) the next one is CHS(1,0,1). In a way this is similar HH:MM:SS.
code :
C = (LBA ÷ SPT) ÷ HPC
H = (LBA ÷ SPT) mod HPC
S = (LBA mod SPT) + 1

HPC = Heads per cylinder (aka Number of Heads)
SPT = Sectors per Track, 
LBA = logical block address

"mod" is the modulo operator (to get the remainder of a division)
LBA =    0:   CHS = ( 0,  0,  1)
LBA =    1:   CHS = ( 0,  0,  2)
LBA =    2:   CHS = ( 0,  0,  3)
LBA =    3:   CHS = ( 0,  0,  4)
LBA =    4:   CHS = ( 0,  0,  5)
LBA =    5:   CHS = ( 0,  0,  6)
LBA =    6:   CHS = ( 0,  0,  7)
LBA =    7:   CHS = ( 0,  0,  8)
LBA =    8:   CHS = ( 0,  0,  9)
LBA =    9:   CHS = ( 0,  0, 10)
LBA =   10:   CHS = ( 0,  0, 11)
LBA =   11:   CHS = ( 0,  0, 12)
LBA =   12:   CHS = ( 0,  0, 13)
LBA =   13:   CHS = ( 0,  0, 14)
LBA =   14:   CHS = ( 0,  0, 15)
LBA =   15:   CHS = ( 0,  0, 16)
LBA =   16:   CHS = ( 0,  0, 17)
LBA =   17:   CHS = ( 0,  0, 18)
LBA =   18:   CHS = ( 0,  1,  1)
LBA =   19:   CHS = ( 0,  1,  2)
LBA =   20:   CHS = ( 0,  1,  3)
LBA =   21:   CHS = ( 0,  1,  4)
LBA =   22:   CHS = ( 0,  1,  5)
LBA =   23:   CHS = ( 0,  1,  6)
LBA =   24:   CHS = ( 0,  1,  7)
LBA =   25:   CHS = ( 0,  1,  8)
LBA =   26:   CHS = ( 0,  1,  9)
LBA =   27:   CHS = ( 0,  1, 10)
LBA =   28:   CHS = ( 0,  1, 11)
LBA =   29:   CHS = ( 0,  1, 12)
LBA =   30:   CHS = ( 0,  1, 13)
LBA =   31:   CHS = ( 0,  1, 14)
LBA =   32:   CHS = ( 0,  1, 15)
LBA =   33:   CHS = ( 0,  1, 16)
LBA =   34:   CHS = ( 0,  1, 17)
LBA =   35:   CHS = ( 0,  1, 18)
LBA =   36:   CHS = ( 1,  0,  1)
LBA =   37:   CHS = ( 1,  0,  2)
LBA =   38:   CHS = ( 1,  0,  3)
LBA =   39:   CHS = ( 1,  0,  4)
LBA =   40:   CHS = ( 1,  0,  5)
LBA =   41:   CHS = ( 1,  0,  6)

... [snip] ...

LBA = 2859:   CHS = (79,  0, 16)
LBA = 2860:   CHS = (79,  0, 17)
LBA = 2861:   CHS = (79,  0, 18)
LBA = 2862:   CHS = (79,  1,  1)
LBA = 2863:   CHS = (79,  1,  2)
LBA = 2864:   CHS = (79,  1,  3)
LBA = 2865:   CHS = (79,  1,  4)
LBA = 2866:   CHS = (79,  1,  5)
LBA = 2867:   CHS = (79,  1,  6)
LBA = 2868:   CHS = (79,  1,  7)
LBA = 2869:   CHS = (79,  1,  8)
LBA = 2870:   CHS = (79,  1,  9)
LBA = 2871:   CHS = (79,  1, 10)
LBA = 2872:   CHS = (79,  1, 11)
LBA = 2873:   CHS = (79,  1, 12)
LBA = 2874:   CHS = (79,  1, 13)
LBA = 2875:   CHS = (79,  1, 14)
LBA = 2876:   CHS = (79,  1, 15)
LBA = 2877:   CHS = (79,  1, 16)
LBA = 2878:   CHS = (79,  1, 17)
LBA = 2879:   CHS = (79,  1, 18)

Why does int 10h not work after reading sectors with int 13h?


By : user2661196
Date : March 29 2020, 07:55 AM
help you fix your problem TL;DR The primary problem with your code as @jester pointed out is that you used an org 0x7c00 which means all absolute references are relative to 0x7c00. When you copy to 0x7a00 the code you generated is still referencing 0x7c?? addresses. When you overwrite memory at 0x7c00 the references to labels like error_msg, BS_DriveNum are to data that has been replaces, and it fails.
code :
;-------------------------------------------------------------------------------
; boot.asm - First boot sector
;-------------------------------------------------------------------------------

org 0x7a00
bits 16

    jmp     word _start

;-------------------------------------------------------------------------------
; BIOS Parameter Block (FAT32)
;-------------------------------------------------------------------------------

BS_OEMName:                     db              "TestOS  "
BPB_BytesPerSector:             dw              512
BPB_SectorsPerCluster:          db              1
BPB_ReservedSectors:            dw              4
BPB_FATCount:                   db              2
BPB_RootEntryCount:             dw              0
BPB_TotalSectors16:             dw              0
BPB_Media:                      db              0xf0
BPB_FATSize16:                  dw              0
BPB_SectorsPerTrack:            dw              18
BPB_HeadCount:                  dw              2
BPB_HiddenSectors:              dd              0
BPB_TotalSectors32:             dd              2880
BPB_FATSize32:                  dd              23
BPB_ExtendedFlags:              dw              0x0000
BPB_FileSystemVersion:          dw              0
BPB_RootCluster:                dd              2
BPB_FSInfo:                     dw              3
BPB_BackupBootSector:           dw              0
BPB_Reserved:                   times 12 db     0
BS_DriveNum:                    db              0x00
BS_Reserved1:                   db              0x0
BS_BootSignature:               db              0x29
BS_VolumeID:                    dd              0x12345678
BS_VolumeLabel:                 db              "TestOS     "
BS_FileSystemType:              db              "FAT32   "

;-------------------------------------------------------------------------------

_start:
; Initialize segment registers and set up stack at 0x7c00 (grows downwards)
    cli
    xor     ax, ax
    mov     ds, ax
    mov     es, ax
    mov     ss, ax
    mov     sp, 0x7a00
    sti

; Save drive number in DL
    mov     [BS_DriveNum], dl

; Copy this boot sector from 0x7c00 to 0x7a00
    mov     si, 0x7c00
    mov     di, 0x7a00
    mov     cx, 512
    cld
    rep movsb

; Jump to the new location
    jmp     0x0000:(_continue)

_continue:

; Reset boot disk (try it 3 times before error message is printed)
    mov     si, 4

_reset:
    mov     ah, 0
    mov     dl, [BS_DriveNum]
    int     0x13

; Load second boot sector into memory at 0x7c00 (try it 3 times before error message is printed)
_load:
    dec     si
    je      _error
    mov     ah, 0x02
    mov     al, 2
    mov     ch, 0
    mov     cl, 3
    mov     dh, 0
    mov     dl, [BS_DriveNum]
    mov     bx, 0x7c00
    int     0x13
    jc      _load

    mov     si, loaded_msg
    call    print

; Jump to the second boot sector
    jmp     0x0000:0x7c00

; End of program
_end:
    hlt
    jmp     _end

_error:
    mov     si, error_msg
    call    print

    jmp     _end

;-------------------------------------------------------------------------------
; Prints a zero-terminated string onto the screen
; SI = string to write
;-------------------------------------------------------------------------------

print:
    pusha
.print_lbl:
    lodsb
    cmp     al, 0
    je      .finished
    mov     ah, 0x0e
    mov     bl, 0
    int     0x10
    jmp     .print_lbl

.finished:
    popa

    ret

;-------------------------------------------------------------------------------

loaded_msg:             db              "Operating system loaded", 0xa, 0xd, 0x0
error_msg:              db              "Operating system not found", 0xa, 0xd, "Press Ctrl+Alt+Del to reboot", 0x0

; Fill the rest of the 512 bytes with 0, byte 510 and 511
; contains 0xaa55 (boot signature for BIOS)

times 510 - ($ - $$) db 0
dw 0xaa55
;-------------------------------------------------------------------------------
; boot.asm - First boot sector
;-------------------------------------------------------------------------------

org 0x00
bits 16

    jmp     word _start

;-------------------------------------------------------------------------------
; BIOS Parameter Block (FAT32)
;-------------------------------------------------------------------------------

BS_OEMName:                     db              "TestOS  "
BPB_BytesPerSector:             dw              512
BPB_SectorsPerCluster:          db              1
BPB_ReservedSectors:            dw              4
BPB_FATCount:                   db              2
BPB_RootEntryCount:             dw              0
BPB_TotalSectors16:             dw              0
BPB_Media:                      db              0xf0
BPB_FATSize16:                  dw              0
BPB_SectorsPerTrack:            dw              18
BPB_HeadCount:                  dw              2
BPB_HiddenSectors:              dd              0
BPB_TotalSectors32:             dd              2880
BPB_FATSize32:                  dd              23
BPB_ExtendedFlags:              dw              0x0000
BPB_FileSystemVersion:          dw              0
BPB_RootCluster:                dd              2
BPB_FSInfo:                     dw              3
BPB_BackupBootSector:           dw              0
BPB_Reserved:                   times 12 db     0
BS_DriveNum:                    db              0x00
BS_Reserved1:                   db              0x0
BS_BootSignature:               db              0x29
BS_VolumeID:                    dd              0x12345678
BS_VolumeLabel:                 db              "TestOS     "
BS_FileSystemType:              db              "FAT32   "

;-------------------------------------------------------------------------------

_start:
; Initialize segment registers and set up stack at 0x7c00 (grows downwards)
    cli
    mov     ax, 0x7c0
    mov     ds, ax
    mov     ss, ax

    xor     ax, ax
    mov     sp, 0x7a00
    sti

; Save drive number in DL
    mov     [BS_DriveNum], dl

; Copy this boot sector from 0x7c00 to 0x7a00
    mov     ax, 0x7a0
    mov     es, ax
    xor     si, si
    xor     di, di
    mov     cx, 512
    cld
    rep movsb

; Jump to the new location
    jmp     0x07a0:(_continue)

_continue:

    mov     ax, 0x7c0
    mov     es, ax
    mov     ax, 0x7a0
    mov     ds, ax

; Load second boot sector into memory at 0x7c00 (try it 3 times before error message is printed)
    mov     si, 4

; Reset boot disk
_reset:
    mov     ah, 0
    mov     dl, [BS_DriveNum]
    int     0x13

_load:
    dec     si
    je      _error
    mov     ah, 0x02
    mov     al, 2
    mov     ch, 0
    mov     cl, 3
    mov     dh, 0
    mov     dl, [BS_DriveNum]
    xor     bx, bx
    int     0x13
    jc      _load

    mov     si, loaded_msg
    call    print

; Jump to the second boot sector
    jmp     0x0000:0x7c00

; End of program
_end:
    hlt
    jmp     _end

_error:
    mov     si, error_msg
    call    print

    jmp     _end

;-------------------------------------------------------------------------------
; Prints a zero-terminated string onto the screen
; SI = string to write
;-------------------------------------------------------------------------------

print:
    pusha
.print_lbl:
    lodsb
    cmp     al, 0
    je      .finished
    mov     ah, 0x0e
    mov     bl, 0
    int     0x10
    jmp     .print_lbl

.finished:
    popa

    ret

;-------------------------------------------------------------------------------

loaded_msg:             db              "Operating system loaded", 0xa, 0xd, 0x0
error_msg:              db              "Operating system not found", 0xa, 0xd, "Press Ctrl+Alt+Del to reboot", 0x0

; Fill the rest of the 512 bytes with 0, byte 510 and 511
; contains 0xaa55 (boot signature for BIOS)

times 510 - ($ - $$) db 0
dw 0xaa55
BOOT_ORG EQU 0x7c00

;-------------------------------------------------------------------------------
; boot.asm - First boot sector
;-------------------------------------------------------------------------------

org BOOT_ORG
bits 16

    jmp     word _start

;-------------------------------------------------------------------------------
; BIOS Parameter Block (FAT32)
;-------------------------------------------------------------------------------

BS_OEMName:                     db              "TestOS  "
BPB_BytesPerSector:             dw              512
BPB_SectorsPerCluster:          db              1
BPB_ReservedSectors:            dw              4
BPB_FATCount:                   db              2
BPB_RootEntryCount:             dw              0
BPB_TotalSectors16:             dw              0
BPB_Media:                      db              0xf0
BPB_FATSize16:                  dw              0
BPB_SectorsPerTrack:            dw              18
BPB_HeadCount:                  dw              2
BPB_HiddenSectors:              dd              0
BPB_TotalSectors32:             dd              2880
BPB_FATSize32:                  dd              23
BPB_ExtendedFlags:              dw              0x0000
BPB_FileSystemVersion:          dw              0
BPB_RootCluster:                dd              2
BPB_FSInfo:                     dw              3
BPB_BackupBootSector:           dw              0
BPB_Reserved:                   times 12 db     0
BS_DriveNum:                    db              0x00
BS_Reserved1:                   db              0x0
BS_BootSignature:               db              0x29
BS_VolumeID:                    dd              0x12345678
BS_VolumeLabel:                 db              "TestOS     "
BS_FileSystemType:              db              "FAT32   "

;-------------------------------------------------------------------------------

_start:
; Initialize segment registers and set up stack at 0x7c00 (grows downwards)
    cli
    xor     ax, ax
    mov     ds, ax
    mov     es, ax
    mov     ss, ax
    mov     sp, 0x7a00
    sti

; Save drive number in DL
    mov     [BS_DriveNum], dl

; Copy this boot sector from 0x7c00 to 0x7a00
    mov     si, 0x7c00
    mov     di, 0x7a00
    mov     cx, 512
    cld
    rep movsb

; Jump to the new location
    jmp     0x0000:_continue

; The code and data past this point will have an origin point (vstart)
; relative to 0x7a00. Align=1 for no padding.

section bootreloc vstart=(($-$$)+0x7a00) align=1
_continue:

; Load second boot sector into memory at 0x7c00 (try it 3 times before error message is printed)
    mov     si, 4

; Reset boot disk
_reset:
    mov     ah, 0
    mov     dl, [BS_DriveNum]
    int     0x13

_load:
    dec     si
    jz      _error
    mov     ah, 0x02
    mov     al, 2
    mov     ch, 0
    mov     cl, 3
    mov     dh, 0
    mov     dl, [BS_DriveNum]
    mov     bx, 0x7c00
    int     0x13
    jc      _load

    mov     si, loaded_msg
    call    print

; Jump to the second boot sector

    jmp     0x0000:0x7c00

; End of program
_end:
    hlt
    jmp     _end

_error:
    mov     si, error_msg
    call    print

    jmp     _end

;-------------------------------------------------------------------------------
; Prints a zero-terminated string onto the screen
; SI = string to write
;-------------------------------------------------------------------------------

print:
    pusha
.print_lbl:
    lodsb
    cmp     al, 0
    je      .finished
    mov     ah, 0x0e
    mov     bl, 0
    int     0x10
    jmp     .print_lbl

.finished:
    popa

    ret

;-------------------------------------------------------------------------------

loaded_msg:             db              "Operating system loaded", 0xa, 0xd, 0x0
error_msg:              db              "Operating system not found", 0xa, 0xd, "Press Ctrl+Alt+Del to reboot", 0x0

; Set position to 510 bytes from BOOT_ORG so that bytes 510 and 511
; in te disk image will contain 0xaa55 (boot signature for BIOS)

section bootsig start=(BOOT_ORG+510)
dw 0xaa55

int 13h not reading sectors from virtual disk


By : Bstbongani thatobst
Date : March 29 2020, 07:55 AM
wish helps you The primary problem is that you are reading from the wrong place on the disk. If you place your second stage starting at the second sector of the disk right after the boot sector, that is Cylinder/Head/Sector (CHS) = (0,0,2). The boot sector is (0,0,1). Sector numbers start at 1, while cylinder and head numbering start at 0.
Other potential issues are (many of which can be found in my General Bootloader tips):
Related Posts Related Posts :
  • Is there any way to iterate through a struct?
  • My character counting code is miscounting characters. Why?
  • Difference between std::resize(n) and std::shrink_to_fit in C++?
  • Wildcard for C++ concepts saying "accepting anything for this template argument"
  • Which of the objects of the class A would be created first in this code snippet?
  • Floating point math accuracy, c++ vs fortran
  • C++ initialize objects with packed array of integers
  • Picking a constructor to call
  • using function call in constructor gives different result c++
  • Using strcpy to copy elements of an char array to another array
  • Templated Constructor Specialization
  • Struggling to convert an integer into a linked list. Not sure what I'm doing wrong here
  • C++: Is it better to store a console output in a macro?
  • C++ - Exception in Constructor
  • AVX: matrix dot vector, but ignore diagonal
  • Pointer To Pointer passed by reference
  • Why is this operator< overload function invisible to STL algorithms?
  • What is the correct algorithm to perform double-float division?
  • In the case of using a std::unique_ptr to automatically deallocate memory upon exiting a scoped block, why not just use
  • C++: Iterating over a string vector and using the index for putenv
  • OpenCL Matrix Multiplication Using std::vector
  • template template parameter deduction: three different compilers three different behaviors
  • C++ pull a card from deck
  • File reading with and without new line
  • store strings in stable memory in c++
  • Why is static_cast used in QT's official document
  • iterator .end() from std::list returns "0xcdcdcdcdcdcdcdcd" but .begin() as expected
  • Is std::sqrt the same as sqrt in C++
  • Iterate through std::initializer_list
  • Codeblocks c++ code doesn't run in VS 19 (vector subscript out of range)
  • Why erase on std::vector promote iterator
  • how to destroy an object in C++
  • How to create Visual Studio 2015 solution from CMake
  • Using concepts for checking if a type T has a field F
  • constructor giving error: no matching function for call to
  • search top n% of a vector member C++
  • Is this reinterpret_cast problematic in principle, and/or in practice?
  • What is the following error doing? I do not see any error with the bounds
  • Two index's of an array have same memory adress
  • how do i avoid integer division in c++?
  • Setting value to enum
  • Properties of a pointer to a zero length array
  • Why the output is different how ever the formula is the same?
  • Restarting from the beginning using do while loops
  • Error: invalid initialization of reference of type
  • how to avoid to use memcpy to create a string
  • Copying the vector elements into std::array
  • Is there any class pointers in Perl in order to access member variables and functions?
  • Why the static variable is not set to 1000
  • Why can't a destructor have reference qualifiers?
  • How to print binary tree in horizontal way?
  • Comparison behavior of ' <' operator
  • Constructors in C++ Language
  • Why displayed value of b , c and y is different from my trace?
  • Undefined reference to `fftw_init_threads' while installing pHash library
  • why the result is 1?
  • YouCompleteMe conf file for inspecting libraries header files without reporting the library errors
  • How CMake finds packages
  • Get UTC epoch time till start of current year in C++
  • access to iterator in lambda function of an algorithm cause me segmentation fault
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org