Page 1 of 1

Problem with executing .com files

Posted: Mon Mar 19, 2012 11:54 am
by Milan
Hi,
I have problems with loading com files in my os.
The problem is:
my os normally execute com file wich file size is les than 100 bytes but when i
try to load com file wich file size is 2KB then system block...
This is a code:

Code: Select all

load_com_file:
        mov ax, input
        mov cx, 5000h ; segment
	call load_com_file_fat
	je fail
	cli
	
	mov ax, 5000h
	mov es, ax
	
	mov     ax, es
        sub      ax, 10h                 ; "org 100h" stuff :)
        mov     es, ax
        mov     ds, ax
        mov     ss, ax
        xor      sp, sp

        push    0x0010                
        push    es
        push    word 100h

        sti
        retf


What can be a problem...

Re: Problem with executing .com files

Posted: Mon Mar 19, 2012 12:03 pm
by Nable
As far as i remember, com programs are loaded from the offset 0x100 in the segment. So, you mustn't sub 0x10 from segment regs.
E.g.: program is loaded from disk to 0x5000:0x0100 and when you jump to it, it must see CS=0x5000, IP=0x0100, but it seems to me that you load file to 0x5000:0x0000 and program has CS=DS=ES=0x4F00 and IP=0x0000 and it's wrong.

Re: Problem with executing .com files

Posted: Mon Mar 19, 2012 12:09 pm
by Combuster
There's nothing in that code in particular that seems to cause that failure. There are several other issues though:

- You didn't write the code or you don't sufficiently know what it does. There are too many dummy moves and indentation errors around AX and ES.
- The typical (expected) status flag if used is CF (which gets set on error), you're checking ZF instead.
- You haven't posted the code for actually loading the file.

@nable: image at 0x5000, which gets bootstrapped with a far return to 4ff0:0100 (i.e. jumps to the first byte of the image while making sure the org directive matches)

Re: Problem with executing .com files

Posted: Mon Mar 19, 2012 3:02 pm
by Milan
I found a problem.
Problem is in my fat driver i try to read sectors where is one com file and it works...