Why INT 13 cannot put data at end of segment in RMode?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
donggas90
Member
Member
Posts: 38
Joined: Fri Oct 17, 2014 12:07 pm

Why INT 13 cannot put data at end of segment in RMode?

Post by donggas90 »

Code: Select all

mov dl, byte[DiskNumber]
mov si, AddressPacket
mov byte[si + SDiskAddressPacket.mSizeOfPacket], 16
mov byte[si + SDiskAddressPacket.mReserved], 0
mov word[si + SDiskAddressPacket.mReadSectorCount], 1
mov word[si + SDiskAddressPacket.mTargetOffset], 0x10000 - 2048
mov word[si + SDiskAddressPacket.mTargetSegment], 0x3F
mov dword[si + SDiskAddressPacket.mSectorIndex], 1
mov dword[si + SDiskAddressPacket.mSectorIndexHigh], 0
call IO_ExtendedReadSectors16 ; call INT 13 Function 42
jc FailReadDiskFailed16
In curiously, I had been tried above code in VMware, to fill end of a segment with a sector.
but just stopped after launch.
NOT fault occured, NOT returned failed signal with carry flag.
Just stucked.

Then had been tested other cases and recognized that cannot put in last approximately* 60bytes of a segment.
(*sometimes worked 59bytes from end of segment.)

Why this happened? Is it normal case?

Thanks!
Last edited by donggas90 on Thu Nov 06, 2014 7:08 am, edited 1 time in total.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Why INT 13 cannot put data at end of segment in RMode?

Post by Combuster »

My crystal ball thinks there's a stack there.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
donggas90
Member
Member
Posts: 38
Joined: Fri Oct 17, 2014 12:07 pm

Re: Why INT 13 cannot put data at end of segment in RMode?

Post by donggas90 »

Combuster wrote:My crystal ball thinks there's a stack there.

Code: Select all

xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

mov ss, ax
not ax
mov sp, ax
Good point.
I had been edited that part of sample code.
because already tried other segments such as 0x3F, 0xFF, 0xFFF what are far from start of memory with target segment but same result occured.
donggas90
Member
Member
Posts: 38
Joined: Fri Oct 17, 2014 12:07 pm

Re: Why INT 13 cannot put data at end of segment in RMode?

Post by donggas90 »

Maybe this is a complex problem.

At last, I'm thinking INT 13 wasn't real reason by Combuster's answer.
Now will figure out exact reason myself.

Thanks for regard!
User avatar
JAAman
Member
Member
Posts: 879
Joined: Wed Oct 27, 2004 11:00 pm
Location: WA

Re: Why INT 13 cannot put data at end of segment in RMode?

Post by JAAman »

donggas90 wrote:

Code: Select all

xor ax, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax

mov ss, ax
not ax
mov sp, ax
thats not really a good way to do the stack...

2 problems:
1) you have an invalid stack for one instruction: mov sp should always immediately follow mov ss.... always, no exceptions (the CPU always suspends interrupts for the one instruction following any move into SS since it expects the next instruction must be a mov to SP to make the stack correct)

2) your stack is misaligned, which , while legal, is not good -- you should be loading SP with 0 instead (remember, SP points at the previous entry, so it will be decremented before storing value, so setting SP = 0, will result in the first value being stored at 0xFFFE/0xFFFF -- at the top of the segment, which is probably what you wanted anyway


simply removing the "not ax" line would fix both of these problems
donggas90
Member
Member
Posts: 38
Joined: Fri Oct 17, 2014 12:07 pm

Re: Why INT 13 cannot put data at end of segment in RMode?

Post by donggas90 »

Wow, Thanks JAAman.

Good informations!
I will fix them!
Post Reply