Problem with executing .com files

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
Milan
Posts: 9
Joined: Sun Jan 01, 2012 7:23 am

Problem with executing .com files

Post 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...
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Problem with executing .com files

Post 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.
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: Problem with executing .com files

Post 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)
"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 ]
Milan
Posts: 9
Joined: Sun Jan 01, 2012 7:23 am

Re: Problem with executing .com files

Post 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...
Post Reply