flat assembler
Message board for the users of flat assembler.

Index > OS Construction > Strange problem... probably with the Stack

Author
Thread Post new topic Reply to topic
j.vimal



Joined: 19 Mar 2006
Posts: 4
j.vimal 19 Mar 2006, 11:48
Hi
I wanted to make a full fledged kernel loader, that would present a prompt (Linux like ) in the beginning and allow me to browse through a FAT32 file system, and tell it what to load.

For that, I wrote a decent MBR, with all details pertaining to a FAT file system embedded on it, like the Bios parameter block etc, that corresponds to a 124 MB USB disk. (Stole it from my previous MBR )

Secondly, I put my program at sector 12, (zero based index), just after some wierd info ...
My program is 2 KB long.
The MBR would load this sector 12 at 0x0:7E00 (just below the MBR) and jump to it.
Everything goes fine till this point.

The program also loads successfully. While executing, I just wanted to load 512 bytes of the FAT into the memory.
(see code).
It too loads successfully.
I type 'd' at the prompt (just one command that I have added) to dump the FAT on to the screen. I should be getting values ... I got some. Fine till now...
The problem is:

the next time I press 'd', it dumps some values and gets stuck.

I think this is some stack related problem. or, it doesnt return to the executing code properly. Could you please check it for me?

Thanks
Vimal


Description: Attached File
Download
Filename: main.asm
Filesize: 6.52 KB
Downloaded: 332 Time(s)

Post 19 Mar 2006, 11:48
View user's profile Send private message Reply with quote
Dex4u



Joined: 08 Feb 2005
Posts: 1601
Location: web
Dex4u 19 Mar 2006, 22:45
If something works once, but not the second time its called, its usually because there was some value left in a reg or var from the call before, try clearing them each time they are called.
I have no time now to study your code, may get time latter.
Post 19 Mar 2006, 22:45
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Mar 2006, 23:24
Code:
        call _terminal_loop ;The main loop function
        
        hlt     ;Stop
        
;****************************************
;_terminal_loop
;****************************************
_terminal_loop:
        
__loop:
        mov si,prompt
        call printf
        mov si,msg_buffer
        mov byte [ds:si],0      ;Flush out the previous input
        call gets                               ;gets a string into the buffer 
        
        mov si,msg_buffer
        cmp byte [ds:si],'d'
        je dump
        jmp __loop
        
        ret
;****************************************
;dump function
;****************************************
dump:
        ;Dumps the FAT Cache
        call endl
        mov si,FS_Type
        call printf
        ret
    


First time your dump code returns but since you jumped to it instead of call it you return to the HLT instruction. After the execution of HLT (interruptions are not disabled so it stop execution of the program but not for too much time) you enter to the loop again but this time you didn't called _terminal_loop so the next time you return you will return to an unknown address. Check it out.

Regards
[edit]I forgot the fix, replace this:
Code:
        cmp byte [ds:si],'d'
        je dump    
with this:
Code:
        cmp byte [ds:si],'d'
        jne __loop
        call dump    
[/edit]
Post 19 Mar 2006, 23:24
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 20 Mar 2006, 07:52
And on lines 7 and 8 you should have:
Code:
ORG 0x7E00
use16
    


and in every <label> times <number> db <value>
label should have a colon ( : ) following it.

What assembler are you using? Maybe on your assembler it works...
Post 20 Mar 2006, 07:52
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
j.vimal



Joined: 19 Mar 2006
Posts: 4
j.vimal 20 Mar 2006, 11:52
Hey thanks for the help locodelassembly.
Now it works Smile

Anyway, Dex4u, thanks for the reply.

Madis731, I am using NASM, for the time being.
Probably I wouldnt have got this error if I had used FASM, which is a little more advanced in its syntax like calling functions etc.

Thanks a lot!

Vimal
Post 20 Mar 2006, 11:52
View user's profile Send private message Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 20 Mar 2006, 21:54
the colon is not necessary, by the way.
`times' works like db,rb etc. and doesn't require a colon before it
Post 20 Mar 2006, 21:54
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 21 Mar 2006, 07:37
No, TIMES doesn't work like DB or RB. It works this way in NASM but I don't see any reason why it should.
Post 21 Mar 2006, 07:37
View user's profile Send private message Visit poster's website Reply with quote
UCM



Joined: 25 Feb 2005
Posts: 285
Location: Canada
UCM 22 Mar 2006, 01:18
hmm thats odd, it worked before
Post 22 Mar 2006, 01:18
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 22 Mar 2006, 07:44
With fasm it didn't, for sure.
Post 22 Mar 2006, 07:44
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.