flat assembler
Message board for the users of flat assembler.

Index > OS Construction > FAT32 opening files

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 01 May 2013, 17:27
superos,

#DE is a fault, thus iret resumes execution of the faulting div.

BTW #DE is caused not only with division by zero, div dx faults too.
Post 01 May 2013, 17:27
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 01 May 2013, 20:03
exceptions don't work when they're called without some serious intelligence in the handler. if it does work then something is seriously wrong with your code elsewhere.

the reason it's invoked repeatedly is because it doesn't correct the problem. a fault returns to the instruction once the handler has finished. there are a number of things you could do but terminating the task is what most people expect from exception 0.

context is the most important part of knowledge. you need to post the code if you want help.

_________________
byte me.
Post 01 May 2013, 20:03
View user's profile Send private message Visit poster's website Reply with quote
superos



Joined: 24 Apr 2013
Posts: 10
superos 02 May 2013, 12:15
Hello,
at the end of the function I wrote:
Code:
        pop es
        pop ds
        mov ax,1
        sti
        iret    

I've been working. Worse, how will div bl or the other.
Post 02 May 2013, 12:15
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 02 May 2013, 13:00
the iret in the handler does, in fact, return to your code courtesy of exception 0 not having an error code. however, it pops data off the stack corresponding to an exception event resulting in an imbalanced stack.

the CS and FLAGS registers are popped from the stack so if you didn't push them prior to the call then whatever data was on the stack will be written to them. updating CS will cause a jump elsewhere, so your CS value had to have been the same as before. the FLAGS could be anything.

in simplest terms: do not call an interrupt. it has its own issues.

_________________
byte me.
Post 02 May 2013, 13:00
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 02 May 2013, 13:11
you have two options (potentially):

1) if your OS has task switching, terminate the task.
2) freeze the OS in the exception 0 handler. use a cli/jmp $. or hlt if it's available,

_________________
byte me.
Post 02 May 2013, 13:11
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 02 May 2013, 14:44
BAiC

Probably superos meant calls inside the fault handler (rysuj_kwadrat(), przesun_kursor, etc.)

If that OS doesn't have task switching, it may simply terminate offending program and return to whatever has spawned that program. Even DOS is able to do this.

----8<----
superos,

Those cli/sti in your handler are superfluous. Handler (in real-address mode) starts with interupts disabled, and iret restores flags from stack.

Recovering from #DE is not an easy task. Most OSes treat it as program (programmer?) failure and kill it. While it's possible to decode faulting instruction and try to correct its operands, it's hard to make it reasonably (I mean that program will not fail due to corrections made). You may as well just skip it, like in the following code:
Code:
        org     0x100
        xor     ax, ax
        mov     es, ax
        mov     word [es:0], handler
        mov     word [es:2], cs
        div     dx
        mov     ah, 9
        mov     dx, [message]
        int     0x21
        ret

message dw      not_signaled
not_signaled db "#DE isn't signaled", 13, 10, "$"
signaled db "Happily skipped 'div' instruction.", 13, 10, "$"

handler:
        push    bp
        mov     bp, sp
        mov     [cs:message], signaled
        add     word [bp+2], 2; skip 'div dx'; it has two-byte opcode
        pop     bp
        iret    
Post 02 May 2013, 14:44
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC 02 May 2013, 15:27
baldr: look at superos' previous post:
Quote:
If I call it the "call" works fine, but if by "mov al, 0 div al"

_________________
byte me.
Post 02 May 2013, 15:27
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:  
Goto page Previous  1, 2

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.