having trouble preserving flags through IRET

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
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

having trouble preserving flags through IRET

Post by Firestryke31 »

I've abandoned trying to keep Socks in 512 bytes, which has allowed me to add a good number of features I couldn't have before. One of these features I'm struggling with is my system API ISR returning with the Carry or Zero flags set. I can't seem to get the flags past the IRET opcode, no matter what I try. I'm guessing I'm using the wrong stack offset, but I've checked the numbers several times.

Here's what I have (16-bit code):

Code: Select all

paramEDI equ BP+ 0
paramESI equ BP+ 4
paramEBP equ BP+ 8
paramESP equ BP+12
paramEBX equ BP+16
paramEDX equ BP+20
paramECX equ BP+24
paramEAX equ BP+28
intIP equ BP+32
intCS equ BP+34
intEF equ BP+36

socksISR:
	pushad
	mov bp, sp

;; Snip out calling the functions, they work correctly
;; I've very thoroughly tested them and they leave
;; SP and BP exactly as they were.

	pushf
	and byte [intEF], 0xBE
	popf
	pushf
	jnc .noCarry
	or byte [intEF], 0x01
.noCarry:
	popf
	jnz .noZero
	or byte [intEF], 0x40
.noZero:

;; I've also tried this with the same results:
;;  lahf
;;  and ah, 0x41
;;  or [intEF], ah

	mov sp, bp
	popad
	iret
My readFile function worked just fine (it successfully read folders from the disk) before I realized that the flags weren't being returned properly, but now it seems to think that there's always a disk read error, even though Bochs says there aren't. I'm pretty sure that I'm just doing something stupid. Could someone please tell me what it is?
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
Troy Martin
Member
Member
Posts: 1686
Joined: Fri Apr 18, 2008 4:40 pm
Location: Langley, Vancouver, BC, Canada
Contact:

Re: having trouble preserving flags through IRET

Post by Troy Martin »

This is what I do:

Code: Select all

    pop ax	; IP
    pop bx	; CS
    pop cx	; Old FLAGS

    pushf		; Push new FLAGS
    push bx		; CS
    push ax		; IP

    iret
Image
Image
Solar wrote:It keeps stunning me how friendly we - as a community - are towards people who start programming "their first OS" who don't even have a solid understanding of pointers, their compiler, or how a OS is structured.
I wish I could add more tex
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: having trouble preserving flags through IRET

Post by Firestryke31 »

I was trying to preserve the other flags, but on further review they don't exactly matter, so I'll try that. I hope it works.

Edit: That actually won't work due to the pushad/popad. But I'll try not preserving the other flags anyway and see how that goes.

Edit II: The Solution:

Here's the code I ended up using:

Code: Select all

	pushf
	pop ax
	mov [intEF], ax
Much simpler, and it works. I think in my old code I needed to use [intEF+1] instead.

Now I just have to find why my attempts to fail to run a program fail. But that's probably a different topic.
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
Post Reply