Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

EIDL version 1.0.0 released (Announce)

posted by rr Homepage E-mail, Berlin, Germany, 20.02.2020, 15:44

> > See it as little ASM example, because it is not as advanced as all the
> > other DOS idlers including Eric Auer's FDAPM.
>
> Thanks!
>
> I wonder a bit why the code sequence
>
> sti
> hlt
>

> does work. In both docs, Intel & AMD, it is pointed out that the STI opcode
> will
> have a "delayed" effect, so interrupts are enabled after the next
> instruction only. Obviously HLT is a special case.

Quoting https://lists.freebsd.org/pipermail/freebsd-current/2004-June/029369.html:
Now, there's a problem... the problem is that if you enable interrupts
and halt (to wait for the next interrupt), then there is a one-instruction
window where an interrupt might occur *BEFORE* you HLT. This interrupt
may do something (such as schedule a thread) that means that you really
don't want to halt now waiting for a *SECOND* interrupt to occur.

In order to deal with this problem, Intel specified that the 'STI ; HLT'
sequence of instructions will *GUARENTEE* that interrupts will remain
disabled for one additional cycle, which gives HLT a chance to enter into
its wait state. An interrupt occuring in between the STI and HLT would
therefore cause the HLT to resume.

In later cpu's Intel and Amd both guarentee the atomicy of the
STI; HLT instruction combination. No interrupt will be allowed to
take effect inbetween the instructions, no trap will occur. No NMI
will occur... nothing (either that or, for an NMI, the cpu will fixup
the interrupt flag and set the restart point to the STI rather then the
HLT).

For all intents and purposes you should treat 'STI; HLT' as a single
instruction.


> It's also a mystery to me when and how often Int 28h is called. IMO it's
> called even if DOS is not "idle" at all. This little program below just
> displays a string via DOS until terminated by Ctrl-C. I runs significantly
> slower if EIDL (or any other idle tool) is installed.
>
> ;--- create binary with "jwasm -mz forever.asm"
> .286
> .model small
> .stack 1024
>
> .data
> text db "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
> db "abcdefghijklmnopqrstuvwxyz"
> db 0
>
> .code
>
> start:
> mov ax, dgroup
> mov ds, ax
> mov si,offset text
> .while 1
> lodsb
> .if al == 0
> mov si,offset text
> lodsb
> .endif
> mov dl,al
> mov ah, 2
> int 21h
> .endw
> mov ah, 4ch
> int 21h
>
> END start
>


Yes, I noticed this too.

I didn't find it in RBIL now, but I read that INT28h is invoked every 4th character that is written using DOS function 2. So it also affects function 9, because this uses function 2 internally.

Update:
Wasn't in RBIL, but in Vernon Brooks' DOS API notes.
- INT 28h was added in DOS 2.0 to allow the resident print spooler (PRINT.COM) to gain control while DOS is idle.
- The DOS kernel issues INT 28h during the keyboard idle loop and once for every 4 (DOS 2.x and 3.x) or 64 (DOS 4+) characters output via INT 21h function 02h.
- INT 21h function 09h uses the function 02h code internally so strings printed via function 09h also contribute to the INT 28h character output count.

---
Forum admin

 

Complete thread:

Back to the forum
Board view  Mix view
22632 Postings in 2109 Threads, 402 registered users, 413 users online (0 registered, 413 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum