flat assembler
Message board for the users of flat assembler.

Index > OS Construction > CLI and STI information or explanation

Author
Thread Post new topic Reply to topic
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 23 Oct 2004, 23:14
according to a book i read:
CLI: Clear Interrupt Flag
Operation: Clears the IF, to disable maskable external interrupts. (see also STI)

STI: Set Interrupt Flag
Operation: Sets the IF to 1 to enable maskable external interrupts after execution of the next instruction. (see CLI for clear IF)

and i check with the index for interrupt flag and found

IF (Interrupt). Indicates that all external interrupts, such as keyboard entry, are to be processed or ignored.

IF (Interrrupt Flag). Disables interrupts when 0, and enables interrupts when 1. This flag is rarely used in conventional programming.

and i saw from the privalov tetros source

Code:
        cli
        xor     ax,ax
        mov     ss,ax
        mov     ds,ax
        mov     es,ax
        mov     sp,0FFFEh
        sti
        push    ax
        push    start
        retf
start:
    


the thing i am confused is, why we need to CLI when we want to move value into segment registers? and

does this mean, external interrupts (such as keyboard) will make use of our segment registers? upon booting up the OS?

and the solor os also resemble something like this

Code:
;------------------------------------------------------------
; back to code...
; BIOS loads this first  512bytes sector at 0000:7C00h
;-------------------------------------------------------------
boot02:
     cli                     ; please no interupts
;      mov     ax,07C0h
    mov     ax,cs
       mov     ds,ax
       mov     es,ax           ; es same as ds

 mov     [boot_drv],dl   ; save drive #
;------------------------------------------------------
; here we make our own stack
; just under the A000h video memory
;------------------------------------------------------
 mov     ax,09000h       ; segment for stack
 mov     ss,ax
       mov     sp,0F800h       ; offset for stack

      sti                     ; enable ints again
    


and menuet os doesn't have such instruction in its first 512 bytes

sincerely
me
Post 23 Oct 2004, 23:14
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 24 Oct 2004, 07:51
The cli/sti pair are being used because they are modifying the Stack Segment (SS) and Stack Pointer (SP) registers. If an interrupt occurs mid-stack segment/pointer change, it's possible that the system will crash. Any Interrupt Service Routines (ISRs), will use your stack (either in full or just briefly) while servicing the IRQ. So it's really important that a valid stack is accessible while external interrupts are enabled.

The safe bet to just to disable external int's, until you have your stack setup.
Post 24 Oct 2004, 07:51
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 24 Oct 2004, 19:46
thank you,
i guess they should put your statement in book :p
Post 24 Oct 2004, 19:46
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 25 Oct 2004, 02:10
Your book sounds like :"IBM PC Assembly Language and Programming by Peter Abel" ?.

\\\\||////
(@@)
ASHLEY4.
Post 25 Oct 2004, 02:10
View user's profile Send private message Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner 25 Oct 2004, 03:38
ASHLEY4 wrote:

Your book sounds like :"IBM PC Assembly Language and Programming by Peter Abel" ?.


yup, how you know? you own that book also? i got a Fourth Edition here, it is by Peter Abel
Professor Emeritus
British Columbia
Institute of Technology

don't tell me you are Peter Abel??
if it is,
nice to met you Smile
i like people who got lot of knowledge Smile
Post 25 Oct 2004, 03:38
View user's profile Send private message Visit poster's website Reply with quote
ASHLEY4



Joined: 28 Apr 2004
Posts: 376
Location: UK
ASHLEY4 25 Oct 2004, 14:24
No just have the book, have you read this book ?.
http://www.cs.smith.edu/~thiebaut/ArtOfAssembly/artofasm.html
you can ask Randall Hyde ? here: http://board.win32asmcommunity.net/forum.php?f=30

\\\\||////
(@@)
ASHLEY4.
Post 25 Oct 2004, 14:24
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 25 Oct 2004, 19:58
this instruction: mov ss,ax
disables interrupts until the end of next instruction
to make possible to load ss and sp in two consecutive instructions without disabling interrupts.
Post 25 Oct 2004, 19:58
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 25 Oct 2004, 23:18
Octavio wrote:
this instruction: mov ss,ax
disables interrupts until the end of next instruction
to make possible to load ss and sp in two consecutive instructions without disabling interrupts.

I thought that was implementation specific and couldn't be relied upon in all cases? (Please correct me if am wrong).
Post 25 Oct 2004, 23:18
View user's profile Send private message Visit poster's website Reply with quote
Gomer73



Joined: 29 Nov 2003
Posts: 151
Gomer73 26 Oct 2004, 17:34
It should be universally compatible after whichever processor implemented it(386, 486, I forget which one.)

But it is still a pain, because you would have to load another register prior to the move. The following wouldn't work:

mov ss,ax
mov ax,0xf000
mov sp,ax

you would need to do something like:

mov bx,0xf000
mov ss,ax
mov sp,bx
Post 26 Oct 2004, 17:34
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8353
Location: Kraków, Poland
Tomasz Grysztar 26 Oct 2004, 20:38
You can also use "LSS SP,[pointer_variable]" instruction to load both SS and SP with one instruction.
Post 26 Oct 2004, 20:38
View user's profile Send private message Visit poster's website Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 26 Oct 2004, 22:07
Gomer73 wrote:
The following wouldn't work:

mov ss,ax
mov ax,0xf000
mov sp,ax



but the following will work (+386)

mov ss,ax
mov sp,0f000h
Post 26 Oct 2004, 22:07
View user's profile Send private message Visit poster's website Reply with quote
Gomer73



Joined: 29 Nov 2003
Posts: 151
Gomer73 27 Oct 2004, 15:51
Makes since, I forget what instructions can be used where.

Thanks,

...Gomer73
Post 27 Oct 2004, 15:51
View user's profile Send private message Reply with quote
neonz



Joined: 02 Aug 2003
Posts: 62
Location: Latvia
neonz 06 Nov 2004, 18:02
Actually, CLI/STI on modifying stack is only necessary for 8086/8088 CPUs. All newer Intel CPUs AFAIK do that CLI/STI thing automatically.
Post 06 Nov 2004, 18:02
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.