flat assembler
Message board for the users of flat assembler.

Index > OS Construction > PIC, IRQ, IDT, and ISR's...?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
So I've got my os working(32-bit PMode) and the kernel loads it's messages, and system halts...no problem here. I've decided to go back and actually implement a working IDT instead of the temporary one I've been using. But I don't understand how it all works together. According to osdev,
Quote:
Basically, when a key is pressed, the keyboard controller tells a device called the Programmable Interrupt Controller, or PIC, to cause an interrupt. Because of the wiring of keyboard and PIC, IRQ #1 is the keyboard interrupt, so when a key is pressed, IRQ 1 is sent to the PIC. The role of the PIC will be to decide whether the CPU should be immediately notified of that IRQ or not and to translate the IRQ number into an interrupt vector (i.e. a number between 0 and 255) for the CPU's table.
Basically, what I'm wanting is when my kernel is performing its various calculations and routines, if i press a key, all other kernel operations will halt, and the key i type will appear on the screen, then the kernel will resume normal operation. Sounds simple enough, but not really.. I don't want to revert back to 16-bit to use BIOS Interrupts, and I don't want to just be in PMode for the 4GB limit utilizing BIOS or DOS like interrupts. I'm thinking I should have a software interrupt descriptor that calls on a interrupt service routine to perform this action.. but in protected mode, IRQ 1 should call the IDT from what i'm understanding, but how does it know which IDT i'm using to call the service routine. Am I completely way off base here or am I on the right track? I'd appreciate any advice... Thanks..


Description: Here's my code if anyone would like to examine it...
Download
Filename: MyOS.zip
Filesize: 12.76 KB
Downloaded: 240 Time(s)


_________________
It's the desire to learn that leads to success...

http://www.webicomp.com


Last edited by newport on 08 Nov 2014, 22:05; edited 2 times in total
Post 08 Nov 2014, 20:26
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
...so i went back and examined my PIC and according to the code, IRQ 0 should start at IDT 32, IRQ 1-keyboard should be IDT 33 and so on...here's my code..
Code:


                progPIC:
                        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                        ;   Re-Program (ReMap) PIC
                        ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                        pushad

                        mov al, 11h
                        out 20h, al             ;Restart PIC1
                        out 0A0h, al            ;Restart PIC2

                        mov al, 20h             ;Start PIC1 @ 32
                        out 21h, al
                        mov al, 28h             ;Start PIC2 @ 40
                        out 0A1h, al

                        mov al, 04h
                        out 21h, al             ;Setup Cascading
                        mov al, 02h
                        out 0A1h, al

                        mov al, 01h
                        out 21h, al             ;Finish Job
                        out 21h, al

                        mov al, 0FFh            ;Enable IRQs at PICs (Keyboard)
                        out 21h, al
                        out 0A1h, al

                        popad      
    


could I have just answered my own question???
Post 08 Nov 2014, 21:03
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
ok.. this didn't work, i set int 33 to point to isr 33 to simply display the letter 'a' on the screen whenever i press a key but that didn't work.. so back to square one....
Post 08 Nov 2014, 21:09
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
I wrote mine a long time ago, I'll see if I can piece this together for you:

PIC.ASM
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; PIC.asm - Contains the Programmable Interrupt Controller interface routines
;;           for the kernel.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

IRQMap      dd 0FFFFFFFFh   ; 32bit (LSb to MSb) map of IRQs: 1 = Off, 0 = On

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; RemapPICToProtectedMode - Remaps IRQs from the BIOS defaults interrupts to
;;                           INT 20h - 2Fh.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

RemapPICToProtectedMode:

    push eax
    
    mov al,11h              ; Initialization Command Word (ICW) 1
    out 20h,al              ; Into first PIC
    out 0A0h,al             ; Into casscaded second PIC

    mov al,20h              ; Load starting interrupt 20h (ICW2)
    out 21h,al              ; Into first PIC
    mov al,28h              ; Load starting interrupt 28h
    out 0A1h,al             ; Into second PIC

    mov al,04h              ; ICW3
    out 21h,al              ; First PIC
    mov al,02h              ; ICW3
    out 0A1h,al             ; Second PIC

    mov al,01h              ; ICW4
    out 21h,al              ; First PIC
    out 0A1h,al             ; Second PIC
    
    pop eax
    
    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; RemapPICToRealMode - Remaps IRQs from the BIOS defaults interrupts to
;;                           INT 20h - 2Fh.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

RemapPICToRealMode:

    push eax
    
    mov al,11h              ; Initialization Command Word (ICW) 1
    out 20h,al              ; Into first PIC
    out 0A0h,al             ; Into casscaded second PIC

    mov al,08h              ; Load starting interrupt 08h (ICW2)
    out 21h,al              ; Into first PIC
    mov al,70h              ; Load starting interrupt 70h
    out 0A1h,al             ; Into second PIC

    mov al,04h              ; ICW3
    out 21h,al              ; First PIC
    mov al,02h              ; ICW3
    out 0A1h,al             ; Second PIC

    mov al,01h              ; ICW4
    out 21h,al              ; First PIC
    out 0A1h,al             ; Second PIC
    
    pop eax
    
    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DisableAllIRQs - Disables all IRQs regardless of masking:
;;
;; Operation Command Word 1: 
;;
;;  |7|6|5|4|3|2|1|0|  OCW1 - IMR Interrupt Mask Register
;;   | | | | | | | `---- 0 = service IRQ0 or IRQ8, 1 = mask off
;;   | | | | | | `----- 0 = service IRQ1 or IRQ9, 1 = mask off
;;   | | | | | `------ 0 = service IRQ2 or IRQA, 1 = mask off
;;   | | | | `------- 0 = service IRQ3 or IRQB, 1 = mask off
;;   | | | `-------- 0 = service IRQ4 or IRQC, 1 = mask off
;;   | | `--------- 0 = service IRQ5 or IRQD, 1 = mask off
;;   | `---------- 0 = service IRQ6 or IRQE, 1 = mask off
;;   `----------- 0 = service IRQ7 or IRQF, 1 = mask off
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
DisableAllIRQs:

    push eax

    mov al,0FFh             ; Turn all IRQs off             
    out 21h,al              ; First PIC
    out 0A1h,al             ; Second PIC
    
    pop eax

    ret
    
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EnableAllMaskedIRQs - Enables all masked IRQs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EnableAllMaskedIRQs:

    push eax
    push ebx

    cli

    mov ebx,[IRQMap]        ; Load current IRQ bitmap
    mov al,bl               ; First 8 IRQs mapped
    out 021h,al
    
    mov al,bh               ; Second 8 IRQs mapped
    out 0A1h,al
    
    sti
    
    pop ebx
    pop eax

    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EnableAllIRQs - Enables all IRQs.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EnableAllIRQs:

    push eax

    cli

    mov al,0                    ; First 8 IRQs mapped
    out 021h,al
    
    mov al,0                ; Second 8 IRQs mapped
    out 0A1h,al
    
    sti
    
    pop eax

    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; EnableAnIRQ - Enables one IRQ based on 32bits.
;;
;; Input:   EAX contains IRQ number to enable.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

EnableAnIRQ:

    push eax
    push ebx
    push ecx
    
    mov ecx,eax
    mov eax,1
    shl eax,cl
    not eax
    
    and eax,[IRQMap]
    mov [IRQMap],eax
    
    call EnableAllMaskedIRQs
    
    pop ecx
    pop ebx
    pop eax
    
    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; DisableAnIRQ - Disables one IRQ based on 32bits.
;;
;; Input:   EAX contains IRQ number to disable.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

DisableAnIRQ:

    push eax
    push ebx
    push ecx

    mov ebx,eax
    mov eax,1
    mov ecx,ebx
    shl eax,cl

    or  eax,[IRQMap]
    mov [IRQMap],eax
    
    call EnableAllMaskedIRQs
    
    pop ecx
    pop ebx
    pop eax
    
    ret    


I go back and forth between real and protected modes.

I'll get you the ISRs and Keyboard and RTC stuff later....sorry, I have to run.
Post 09 Nov 2014, 18:17
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
l_inc
newport
If you set a bit in the mask, the corresponding interrupt is masked. Therefore you don't receive any interrupts.

And for your own convenience, please, start giving names to bits and enumeration values. Those bare numbers are not readable.

_________________
Faith is a superposition of knowledge and fallacy
Post 09 Nov 2014, 18:49
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
Thank you both for the reply's!
Post 09 Nov 2014, 20:07
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
Interrupt addition and deletion:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; AddISRToIDT - Adds an ISR to the IDT, then reloads the IDT.
;;
;; Assumptions: User has already turned off interrupts.
;;
;; Input:   ESI = Address of ISR
;;          EAX = The number of the IRQ to load
;;
;; Output:  EDI = Address of previous ISR (not functioning yet)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AddISRToIDT:

    mov ebx,eax             ; Copy EAX into EBX
    mov eax,8               ; Place 8 into EAX
    mul ebx                 ; Multiply EAX by EBX to get offset of IRQ in IDT
    mov ebx,eax             ; Copy EAX into EBX
    mov eax,IDTISRStart     ; Load address of starting IRQ in IDT
    add eax,ebx             ; Add offset of IRQ into EAX
    mov ecx,esi             ; Place address of ISR into ECX
    mov [ds:eax],cx         ; Copy lower 16 bits into IDT entry
    shr ecx,16              ; Move upper 16 bits into CX
    mov [ds:eax + 6],cx     ; Copy upper 16 bits into IDT entry

    ret

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; AddExceptionToIDT - Adds an exception ISR to the IDT, then reloads the IDT.
;;
;; Assumptions: User has already turned off interrupts.
;;
;; Input:   ESI = Address of ISR
;;          EAX = The number of the Exception to load
;;
;; Output:  EDI = Address of previous ISR (not functioning yet)
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

AddExceptionToIDT:

    mov ebx,eax             ; Copy EAX into EBX
    mov eax,8               ; Place 8 into EAX
    mul ebx                 ; Multiply EAX by EBX to get offset of IRQ in IDT
    mov ebx,eax             ; Copy EAX into EBX
    mov eax,IDT             ; Load address of starting IRQ in IDT
    add eax,ebx             ; Add offset of IRQ into EAX
    mov ecx,esi             ; Place address of ISR into ECX
    mov [ds:eax],cx         ; Copy lower 16 bits into IDT entry
    shr ecx,16              ; Move upper 16 bits into CX
    mov [ds:eax + 6],cx     ; Copy upper 16 bits into IDT entry

    ret    
Post 10 Nov 2014, 11:03
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
smiddy wrote:
Code:
    mov ebx,eax             ; Copy EAX into EBX
    mov eax,8               ; Place 8 into EAX
    mul ebx                 ; Multiply EAX by EBX to get offset of IRQ in IDT
    mov ebx,eax             ; Copy EAX into EBX
    mov eax,IDTISRStart     ; Load address of starting IRQ in IDT
    add eax,ebx             ; Add offset of IRQ into EAX
    mov ecx,esi             ; Place address of ISR into ECX
    mov [ds:eax],cx         ; Copy lower 16 bits into IDT entry
    shr ecx,16              ; Move upper 16 bits into CX
    mov [ds:eax + 6],cx     ; Copy upper 16 bits into IDT entry

    ret 
    

I don't usually comment on code optimization but I feel this example needs to be simplified.
Code:

    
    lea eax,[ebx*8+IDTISRStart]
    mov ecx,esi             ; Place address of ISR into ECX
    shr ecx,16              ; Move upper 16 bits into CX
    mov [ds:eax + 0],si     ; Copy lower 16 bits into IDT entry
    mov [ds:eax + 6],cx     ; Copy upper 16 bits into IDT entry
        
ret 
    

you don't even need the LEA if you're willing to re-calculate the value for the second write.

btw; DS doesn't need to be explicitly declared. DS is implicitly used when a segment register isn't referenced.

- Stefan

_________________
byte me.
Post 11 Nov 2014, 02:16
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Keep in mind that that only works when the magic value of 8 is hard coded into the source. If it is a defined constant (like say "sizeof.MYSTRUCTURE") then only certain values will work before the assembler complains about being unable to encode it.
Post 11 Nov 2014, 02:43
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
BAiC wrote:
smiddy wrote:
Code:
    mov ebx,eax             ; Copy EAX into EBX
    mov eax,8               ; Place 8 into EAX
    mul ebx                 ; Multiply EAX by EBX to get offset of IRQ in IDT
    mov ebx,eax             ; Copy EAX into EBX
    mov eax,IDTISRStart     ; Load address of starting IRQ in IDT
    add eax,ebx             ; Add offset of IRQ into EAX
    mov ecx,esi             ; Place address of ISR into ECX
    mov [ds:eax],cx         ; Copy lower 16 bits into IDT entry
    shr ecx,16              ; Move upper 16 bits into CX
    mov [ds:eax + 6],cx     ; Copy upper 16 bits into IDT entry

    ret 
    

I don't usually comment on code optimization but I feel this example needs to be simplified.
Code:

    
    lea eax,[ebx*8+IDTISRStart]
    mov ecx,esi             ; Place address of ISR into ECX
    shr ecx,16              ; Move upper 16 bits into CX
    mov [ds:eax + 0],si     ; Copy lower 16 bits into IDT entry
    mov [ds:eax + 6],cx     ; Copy upper 16 bits into IDT entry
        
ret 
    

you don't even need the LEA if you're willing to re-calculate the value for the second write.

btw; DS doesn't need to be explicitly declared. DS is implicitly used when a segment register isn't referenced.

- Stefan


I appreciate the criticism actually. I wrote that about 8 years ago, when I was first learning to code in 32 bit ASM, There are a lot of way to skin a cat. Turpentine is a way, but I wouldn't recommend it. Smile I haven't gotten back around to this part yet in my latest attempt but am getting better in my coding.

Smiddy
Post 11 Nov 2014, 03:15
View user's profile Send private message Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
revolution wrote:
Keep in mind that that only works when the magic value of 8 is hard coded into the source. If it is a defined constant (like say "sizeof.MYSTRUCTURE") then only certain values will work before the assembler complains about being unable to encode it.
Since I have been avoiding structures up to this point, I should be ok. I need to sit down a study structures in FASM. The last time I did them in C was on the order of maybe 20 years ago.
Post 11 Nov 2014, 03:19
View user's profile Send private message Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
revolution wrote:
Keep in mind that that only works when the magic value of 8 is hard coded into the source. If it is a defined constant (like say "sizeof.MYSTRUCTURE") then only certain values will work before the assembler complains about being unable to encode it.


this is why I don't I don't talk about optimization: stupid mother fuckers like revolution twist my comments into something they're not...

I wasn't providing a general optimization example. I was just optimizing a specific program.

_________________
byte me.
Post 11 Nov 2014, 04:57
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17669
Location: In your JS exploiting you and your system
revolution
Treat it as an opportunity to make a macro:
Code:
;...
if sizeof.MYSTRUCTURE in <1,2,3,4,5,8,9>
        lea     eax,[ebx*sizeof.MYSTRUCTURE+IDTISRStart]
else
        mov     eax,sizeof.MYSTRUCTURE
        mul     ebx
        add     eax,IDTISRStart
end if
;...    
Post 11 Nov 2014, 09:01
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
I have no idea what I'm doing wrong.. I've tried to use the suggestions and other posts i've read, and I just can't get it working... i'm so frustrated right now.
Post 12 Nov 2014, 00:25
View user's profile Send private message Visit poster's website Reply with quote
smiddy



Joined: 31 Oct 2004
Posts: 559
smiddy
Here's my clock, uses the above code:
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CLOCK.ASM - Contains the driver code for the OS clock, which is internal
;;             to the kernel at this time. Takes control of the PIT...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Header - This is the header used by smiddyOS device drivers.
;;
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Data elements
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

TimerCounter                            dq 0                                    ; Initialized to zero
Frequency1KHz                           dw 004A9h                               ; Divisor 1193180 / 1193 = 1000
Frequency100Hz                          dw 02E9Bh                               ; Divisor 1193180 / 11931 = 100
Frequency18_2Hz                         dw 0FFFFh                               ; Divisor 1193180 / 65535 = 18.2
ClockInitializationMessage      db 'smiddyOS Clock Initializing...',0
ClockInstalledMessage           db 'Done!',13,10,0
InClockMessage                          db 13,10,'In the clock after 6,000 tics',13,10,0

InitializeClock:

        mov esi,ClockInitializationMessage
        call PrintString32
        
        ; Disable interrupts
        
        cli
        
        ; Disable all IRQs
        
        call DisableAllIRQs
        
        ; Reprogram PIT - 0 for timer of 1/1000 seconds (if possible)
        ; Timer 8253/54 Ports:
        ;   40h    Channel 0 counter (read/write) 
        ;       41h    Channel 1 counter (read/write) 
        ;       42h    Channel 2 counter (read/write) 
        ;       43h    Control Word (write only)      
        ;
        ; Control Word:
        ;  7    6    5    4    3    2    1    0
        ; SC1  SC0  RL1  RL0   M2   M1   M0  BCD
        ;                                     ^
        ;                                     0  Binary Counter
        ;                                     1  BCD (4 decades)
        ;                      ^    ^    ^
        ;                      0    0    0  Mode 0 Interrupt on terminal count
        ;                      0    0    1  Mode 1 Programmable one shot
        ;                      x    1    0  Mode 2 Rate Generator
        ;                      x    1    1  Mode 3 Square wave rate Generator
        ;                      1    0    0  Mode 4 Software triggered strobe
        ;                      1    0    1  Mode 5 Hardware triggered strobe
        ;            ^    ^
        ;            0    0  Counter Latching operation
        ;            0    1  Read/Load LSB Only
        ;            1    0  Read/Load MSB Only
        ;            1    1  Read/Load LSB first, then MSB
        ;  ^    ^
        ;  0    0  Select Counter 0
        ;  0    1  Select Counter 1
        ;  1    0  Select Counter 2
        ;  1    1  Illegal
        
        mov bx,[Frequency18_2Hz]        
        mov al,34h                                      ; Control Word: 00110100b
        out 43h,al                                      ; Out control word port
        mov     al,bl                                   ; LSB in BL
        out     40h,al                                  ; Out channel 0
        mov     al,bh                                   ; MSB in BH
        out     40h,al                                  ; Out channel 0

        ; Reprogram PIT - 1 for timer of 1/18 seconds (DOS)
        
;       mov bx,[Frequency18_2Hz]        
;       mov al,74h                                      ; Control Word: 01110100b
;       out 43h,al                                      ; Out control word port
;       mov     al,bl                                   ; LSB in BL
;       out     41h,al                                  ; Out channel 1
;       mov     al,bh                                   ; MSB in BH
;       out     41h,al                                  ; Out channel 1
        
        ; call API to add IRQ ISR to IDT
        
        mov esi,ClockISR
        mov eax,0
        call AddISRToIDT
        sti
        
        ; Reprogram PIC for IRQ 0
        
        mov eax,0
        call EnableAnIRQ        

        mov esi,ClockInstalledMessage
        call PrintString32
        
        ret
        
ClockISR:

        ; 64-bit timer counter (24hrs/day x 60min/hr x 60sec/min x 1000tics/sec = 86,400,000tics/day)
        ; It can effectively run for 213,503,982,334 days or 584,542,046 years
        ; Will have to use MMX registers or something else.
        pushad
;       push gs
;       push fs
;       push ds
;       push es
        
        add dword [ds:TimerCounter],1           ; 64bit counter variable (there's gotta be a better way)
        adc dword [ds:TimerCounter + 4],0       ; If carry, then add CF and nothing else
        
;       mov eax,dword [TimerCounter]
;       cmp eax,6000                                    ; Check after one minute of install
;       jne .FinishUp
;       
;       mov esi,InClockMessage
;       call PrintString
;       
; .FinishUp:

        mov al,20h                                              ; Send EOI
        out 20h,al                                              ; To PIC
        out 0A0h,al
        

;       pop es
;       pop ds
;       pop fs
;       pop gs
        popad

        iret    


To be honest, I haven't had a chance to open up your file yet. I'll try tomorrow while I'm traveling.
Post 12 Nov 2014, 04:03
View user's profile Send private message Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
Thank you so much smiddy! I'm sure if I could get a simple working example, I could learn how it all fits together to write my own code...it's just most examples i've found on the net include some-sort of C code for doing these things which i'm trying to avoid with my operating system and those which do include assembly have things scattered throughout multiple files which makes it difficult to understand how it all fits together. Thank you for your time...
Post 13 Nov 2014, 00:03
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
I found one error while reading your code:

during Interrupt 33 execution the code fails to initialize the ES register. this can send the "a" character anywhere in memory.

- Stefan

_________________
byte me.
Post 13 Nov 2014, 21:35
View user's profile Send private message Visit poster's website Reply with quote
BAiC



Joined: 22 Mar 2011
Posts: 272
Location: California
BAiC
I'm a bit slow since my focus is on an ACPI AML decoder but I know one very serious bug with your ISRs:

you don't respond to the interrupt controller. it's been awhile since I've actually written the code for it (I currently use an interrupt redirection service that does it automatically). the final instructions before returning (for the 8259 PIC) is:

Code:
mov al, 0x60 + 1;ISR1: the keyboard.
out 0x20, al
    

you then restore the registers and issue an IRET.

_________________
byte me.
Post 14 Nov 2014, 04:25
View user's profile Send private message Visit poster's website Reply with quote
newport



Joined: 08 Jun 2012
Posts: 86
Location: Kentucky, USA
newport
I will give this a try BAiC and see what happens. Thank you all for the help.
Post 14 Nov 2014, 08:51
View user's profile Send private message Visit poster's website Reply with quote
vendu



Joined: 15 Nov 2014
Posts: 2
Location: Finland
vendu
First of all, I just heard about this cool board and this is my first post. I hope it's not too off-topic to link some C code with inline assembly macros, so here you go:

https://github.com/vendu/OS-Zero/blob/master/kern/unit/x86/trap.h

And for more info on how to use this junk:

https://github.com/vendu/OS-Zero/blob/master/kern/unit/x86/trap.c

I hope this helps. Smile

_________________
----8<----

/* vendu */
Post 16 Nov 2014, 00:14
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 1, 2  Next

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

Website powered by rwasa.