Author Topic: Size Testing the Disk Read for BIOS Function Int 13h  (Read 11034 times)

Offline Deskman243

  • Jr. Member
  • *
  • Posts: 49
Size Testing the Disk Read for BIOS Function Int 13h
« on: May 24, 2023, 04:42:46 PM »
I was testing the numbers on a boot I had from a small NASM build. Mainly I was practicing making more space from the 512 boot code from the BIOS 13h function. Curiously my build drops the link to other files at a certain level. I tried squeezing through as much through as I could to get to 512 section right before 0x10000 but I haven't been able to get anything else passed here.

I noticed how al=65 was the highest placement. Figures the computation here was around 66th for the 64kb boundary <=> 0x7C00 +66 (8)(*512b=0x1000)=0x7C00+2*(0x0200)+64(0x0200) . Therefore the cause seems to be related to the int 13 BIOS configuration. The current model is more similar to other sources like wikipedia however I guess I still don't understand what is stopping the function. Here's when I tried calling int 13 from the section right before the gap but now I just keep getting this ld check.

    ld: warning: cannot find entry symbol _start; defaulting to 0000000000010000
    stage2.o:stage2.asm:15:(.text+0xc): relocation truncated to fit: R_386_16 against `.text'
    make: *** [Makefile:27: stage2.bin] Error 1

I'd like to add too that if I change the address variables to before the 64k address (like 0xFC00 <=>64) the code does build. Now my question is on how to use the BIOS 13h for the sections.
Here's the quick version to illustrate the current bug I get.

boot.asm
Code: [Select]

    [BITS 16]
    ;[ORG 0x7c00]
   
    section .text
   
    _prep_module:
        xor ax,ax   
        mov ds,ax
        mov es,ax 
        mov ss,ax
        mov sp,0x7C00
   
    DriveIdPrep:
        mov [DriveId],dl
        mov ah,0x41
        mov bx,0x55aa
        int 0x13
    ;    jc CheckPrep
        cmp bx,0xaa55
    ;    jne CheckPrep
   
    SizeFunction:
    mov bx,0x0000_7E00
    mov cl,2
    mov ah,0x02
    ; mov al,1
    ; mov al,12h
    mov al,65
    mov ch,0
    mov dh,0
        int 0x13
    ;    jc  ReadCheck
   
        mov dl,[DriveId]
   
   
    .move1:
    mov cx,0xfe00
    jmp cx
   
   
    jmp $
   
   
   
    Section .data 
    String: db 'Check',0
    DriveId:    db 0
   
    MessageLen: equ $-String
    ReadPacket: times 16 db 0
   
   
    ROWS EQU 25
    COLS1 EQU 80
    BACK1 EQU 05h
    FRONT1 EQU 12h
    CHECKER EQU 0
   
    Graphics_CTRLA EQU 03CEh
    Sequencer_CTRLA EQU 03C4h
    Crd1Size EQU 640
    HDATA EQU (Crd1Size/8)
    Graph_Segment EQU 0A000H
    crd1 EQU 45
    crd2 EQU 54
    color EQU 05h
   
   
    X dd 0
    Y dd 0
    color_pkg dw 0x05
   
    LoopVar1: db 0
   
    Value1: db 0

link.ld
Code: [Select]

    INPUT (boot.o)
   
   
    OUTPUT_FORMAT(binary)
    OUTPUT_ARCH(i386)
    ENTRY(_prep_module)
   
   
   
   
    SECTIONS
    {
   
   
    . = 0x7c00;
    _premier = .;
    _prep_module =.;
   
   
    .text . :
    {boot.o(.text)}
   
    .rodata : {boot.o(.rodata)}
   
    .data 0x7D00 : {boot.o(.data)}
   
   
   
   
   
    . = _premier + 512*1-2;
    .dummy 0x7dfe : {BYTE(0x55); BYTE(0xaa);}
   
    _bss_premier =.;
    .bss : {*(.bss)}
    _bss_stub = .;
    _heap = .;
    /DISCARD/ : {*(.comment)*(.eh_frame)*(.note.GNU.stack)}
   
   
   
   
    }
stage1.asm
Code: [Select]


    [BITS 16]
   
    ;[BITS 32]
   
    section .text
   
        SizeFunction2:

    xor cx,cx
    push cx
    mov cx,0x1000
    mov es,cx
   
    mov bx,0x0000
    mov cl,2
    mov ah,0x02
    ; mov al,1
    ; mov al,12h
    mov al,66
    mov ch,0
    mov dh,0
        int 0x13
    ;    jc  ReadCheck
    pop cx
    mov es,cx
    ;    mov dl,[DriveId]
   
    mov ax,0
    mov ds,ax
    mov cx,0xb800
    mov es,cx
   
    cld
   
    mov si,String
    call print_str
   
    .move1:
    jmp 0x10000
   
    ; jmp 0xFC00
    ; jmp $
   
    print_str:
    mov ah,0xde
    mov bp,320
    .loop1:
    mov al,byte [ds:si]
    mov es:[bp],ax
    inc si
    ; inc si
    inc bp
    inc bp
    cmp bp,320+StringLen*2
   
    jnz .loop1
   
    ret
   
    ;section .data
    String: db 'test string',0
    StringLen: equ $-String

stage2.asm
Code: [Select]

    [bits 16]
    ;[bits 32]
   
   
    ;_prep_module2:
   
    ;mov ax,0
    mov ax,0x1000
    mov ds,ax
    mov cx,0xb800
    mov es,cx
   
    cld
   
    mov si,String
    call print_str
   
    jmp $
   
   
   
    print_str:
    mov ah,0xde
    mov bp,0
    .loop1:
    mov al,byte [ds:si]
    mov es:[bp],ax
    inc si
    ; inc si
    inc bp
    inc bp
    cmp bp,StringLen*2
   
    jnz .loop1
   
    ret
   
    ;section .data
    String: db 'test string',0
    StringLen: equ $-String


Makefile
Code: [Select]

    FILES =boot.o
    FILES2 =stage2.o
   
    PROCURE = rm -rf
   
    all: boot.bin stage1.bin stage2.bin
    dd if=boot.bin of=os.img bs=512 count=65 conv=notrunc
    dd if=stage1.bin of=os.img bs=512 seek=65 conv=notrunc
    dd if=stage2.bin of=os.img bs=512 seek=66 conv=notrunc   

    boot.o: boot.asm
    nasm -f elf -g -o boot.o boot.asm
    stage1.o: stage1.asm
    nasm -f elf -g stage1.asm -o stage1.o
    stage2.o: stage2.asm
    nasm -f elf -g stage2.asm -o stage2.o
   
    boot.bin: $(FILES)
    ld -T link.ld $(FILES) -o boot.bin
   
    stage1.bin: stage1.o
    ld -g -m elf_i386 -Ttext 0xfe00 stage1.o -o stage1.bin --oformat binary

    stage2.bin: stage2.o
    ld -g -m elf_i386 -Ttext 0x10000 stage2.o -o stage2.bin --oformat binary
       
   
    clean:
    $(PROCURE) *\.o
    $(PROCURE) *\.bin
    $(PROCURE) os.img






Offline alCoPaUL

  • Jr. Member
  • *
  • Posts: 74
  • Country: ph
    • Webpage
Re: Size Testing the Disk Read for BIOS Function Int 13h
« Reply #1 on: June 06, 2023, 03:44:24 PM »
there's this interrupt 13 function that is used to make bad sectors..

like what will happen when you flag the mbr/boot sector as bad sectors?

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 373
  • Country: br
Re: Size Testing the Disk Read for BIOS Function Int 13h
« Reply #2 on: June 06, 2023, 06:56:54 PM »
1. Usually HDs, in CHS scheme, have only 63 sectors per cylinder (1 to 63).
2. Subfunction 0x41, BX=0xaa55 is an EXTENSION which can not be present.

I suggest to use subfunction 0x42 (an IBM/MS extension and present in the majority of AT class machines), using LBA to read sectors.

Offline Deskman243

  • Jr. Member
  • *
  • Posts: 49
Re: Size Testing the Disk Read for BIOS Function Int 13h
« Reply #3 on: June 10, 2023, 12:03:22 AM »
Revision 1
 I managed to make a new remodel fit for a simplified run. Instead of the makefile this build concentrates around changing the ld links through [org ] addresses. What's new is that when I try to access data passed 0xFFFF for say like a standard print method it does in fact run however if I try to call the code itself from the same area I get run discrepancies. I know that BIOS reserve areas are stipulated from around 0xA0000 + however this still leaves atleast 0x90000 potentially unused segments. The fact at hand is I really don't know how the electronics are configured here. I know 8086 has an extra A16-19 data lines that increase the segments from 16 to 20 that is the distinction between 0xFFFF <=> 0xFFFFF.

1. Usually HDs, in CHS scheme, have only 63 sectors per cylinder (1 to 63).
2. Subfunction 0x41, BX=0xaa55 is an EXTENSION which can not be present.

I suggest to use subfunction 0x42 (an IBM/MS extension and present in the majority of AT class machines), using LBA to read sectors.

I would hope that this could answer the above question. Could you provide an illustration of this? If anyone else would a correspondence just let me know and I can post the new model for revision too.