2010-10-02 00:49:29 +04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2015-06-01 22:18:07 +03:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;;
|
2010-10-02 00:49:29 +04:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2014-12-01 06:51:07 +03:00
|
|
|
$Revision: 4850 $
|
|
|
|
|
2010-10-02 00:49:29 +04:00
|
|
|
|
|
|
|
iglobal
|
2011-09-21 17:58:48 +04:00
|
|
|
IRQ_COUNT dd 24
|
2010-10-02 00:49:29 +04:00
|
|
|
endg
|
|
|
|
|
|
|
|
uglobal
|
2011-09-21 17:58:48 +04:00
|
|
|
irq_mode rd 1
|
2011-09-19 22:35:05 +04:00
|
|
|
IOAPIC_base rd 1
|
|
|
|
LAPIC_BASE rd 1
|
2010-10-02 00:49:29 +04:00
|
|
|
endg
|
|
|
|
|
2011-09-21 01:11:22 +04:00
|
|
|
APIC_ID equ 0x20
|
|
|
|
APIC_TPR equ 0x80
|
|
|
|
APIC_EOI equ 0xb0
|
|
|
|
APIC_LDR equ 0xd0
|
|
|
|
APIC_DFR equ 0xe0
|
|
|
|
APIC_SVR equ 0xf0
|
|
|
|
APIC_ISR equ 0x100
|
|
|
|
APIC_ESR equ 0x280
|
|
|
|
APIC_ICRL equ 0x300
|
|
|
|
APIC_ICRH equ 0x310
|
2013-09-14 22:55:13 +04:00
|
|
|
APIC_LVT_LINT0 equ 0x350
|
|
|
|
APIC_LVT_LINT1 equ 0x360
|
2011-09-21 01:11:22 +04:00
|
|
|
APIC_LVT_err equ 0x370
|
2010-10-02 00:49:29 +04:00
|
|
|
|
|
|
|
; APIC timer
|
2013-09-14 22:55:13 +04:00
|
|
|
APIC_LVT_timer equ 0x320
|
|
|
|
APIC_timer_div equ 0x3e0
|
|
|
|
APIC_timer_init equ 0x380
|
|
|
|
APIC_timer_cur equ 0x390
|
2010-10-02 00:49:29 +04:00
|
|
|
; IOAPIC
|
2013-09-14 22:55:13 +04:00
|
|
|
IOAPIC_ID equ 0x0
|
|
|
|
IOAPIC_VER equ 0x1
|
|
|
|
IOAPIC_ARB equ 0x2
|
|
|
|
IOAPIC_REDTBL equ 0x10
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2011-09-21 01:11:22 +04:00
|
|
|
align 4
|
2010-10-02 00:49:29 +04:00
|
|
|
APIC_init:
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [irq_mode], IRQ_PIC
|
2011-09-19 22:35:05 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
cmp [acpi_ioapic_base], 0
|
|
|
|
jz .no_apic
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
cmp [acpi_lapic_base], 0
|
|
|
|
jz .no_apic
|
2011-09-21 17:58:48 +04:00
|
|
|
|
|
|
|
stdcall load_file, dev_data_path
|
2012-03-08 19:49:27 +04:00
|
|
|
test eax, eax
|
|
|
|
jz .no_apic
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [acpi_dev_data], eax
|
|
|
|
mov [acpi_dev_size], ebx
|
2011-09-22 16:21:49 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
call IRQ_mask_all
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2011-09-21 17:58:48 +04:00
|
|
|
; IOAPIC init
|
2015-06-01 22:18:07 +03:00
|
|
|
stdcall map_io_mem, [acpi_ioapic_base], 0x20, PG_GLOBAL+PG_NOCACHE+PG_SWR
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [IOAPIC_base], eax
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov eax, IOAPIC_VER
|
2012-03-08 19:49:27 +04:00
|
|
|
call IOAPIC_read
|
|
|
|
shr eax, 16
|
|
|
|
inc al
|
2012-03-09 12:20:02 +04:00
|
|
|
movzx eax, al
|
2012-03-08 19:49:27 +04:00
|
|
|
cmp al, IRQ_RESERVED
|
|
|
|
jbe @f
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
mov al, IRQ_RESERVED
|
2011-08-27 15:24:26 +04:00
|
|
|
@@:
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [IRQ_COUNT], eax
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Reroute IOAPIC & mask all interrupts
|
2012-03-08 19:49:27 +04:00
|
|
|
xor ecx, ecx
|
|
|
|
mov eax, IOAPIC_REDTBL
|
2011-09-21 01:11:22 +04:00
|
|
|
@@:
|
2012-03-08 19:49:27 +04:00
|
|
|
mov ebx, eax
|
|
|
|
call IOAPIC_read
|
2013-09-14 22:55:13 +04:00
|
|
|
mov ah, 0x08; Delivery Mode: Fixed, Destination Mode: Logical
|
2012-03-08 19:49:27 +04:00
|
|
|
mov al, cl
|
2012-03-08 12:33:38 +04:00
|
|
|
add al, 0x20; vector
|
|
|
|
or eax, 0x10000; Mask Interrupt
|
2012-03-08 19:49:27 +04:00
|
|
|
cmp ecx, 16
|
|
|
|
jb .set
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
or eax, 0xa000;<<< level-triggered active-low for IRQ16+
|
2010-10-02 00:49:29 +04:00
|
|
|
.set:
|
2012-03-08 19:49:27 +04:00
|
|
|
xchg eax, ebx
|
|
|
|
call IOAPIC_write
|
|
|
|
inc eax
|
|
|
|
mov ebx, eax
|
|
|
|
call IOAPIC_read
|
2012-03-08 12:33:38 +04:00
|
|
|
or eax, 0xff000000; Destination Field
|
2012-03-08 19:49:27 +04:00
|
|
|
xchg eax, ebx
|
|
|
|
call IOAPIC_write
|
|
|
|
inc eax
|
|
|
|
inc ecx
|
|
|
|
cmp ecx, [IRQ_COUNT]
|
|
|
|
jb @b
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
call LAPIC_init
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [irq_mode], IRQ_APIC
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
mov al, 0x70
|
|
|
|
out 0x22, al
|
|
|
|
mov al, 1
|
|
|
|
out 0x23, al
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
call pci_irq_fixup
|
2011-09-21 01:11:22 +04:00
|
|
|
.no_apic:
|
|
|
|
|
|
|
|
ret
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2010-10-02 00:49:29 +04:00
|
|
|
;===========================================================
|
|
|
|
align 4
|
|
|
|
LAPIC_init:
|
2012-03-08 19:49:27 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp [LAPIC_BASE], 0
|
|
|
|
jne .done
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2015-06-01 22:18:07 +03:00
|
|
|
stdcall map_io_mem, [acpi_lapic_base], 0x1000, PG_GLOBAL+PG_NOCACHE+PG_SWR
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [LAPIC_BASE], eax
|
|
|
|
mov esi, eax
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Program Destination Format Register for Flat mode.
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, [esi + APIC_DFR]
|
|
|
|
or eax, 0xf0000000
|
|
|
|
mov [esi + APIC_DFR], eax
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Program Logical Destination Register.
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, [esi + APIC_LDR]
|
2011-09-21 01:11:22 +04:00
|
|
|
;and eax, 0xff000000
|
2012-03-08 19:49:27 +04:00
|
|
|
and eax, 0x00ffffff
|
2012-03-08 12:33:38 +04:00
|
|
|
or eax, 0x01000000;!!!!!!!!!!!!
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [esi + APIC_LDR], eax
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Task Priority Register initialization.
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, [esi + APIC_TPR]
|
|
|
|
and eax, 0xffffff00
|
|
|
|
mov [esi + APIC_TPR], eax
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Flush the queue
|
2012-03-08 19:49:27 +04:00
|
|
|
mov edx, 0
|
2011-09-21 01:11:22 +04:00
|
|
|
.nxt2:
|
2012-03-08 19:49:27 +04:00
|
|
|
mov ecx, 32
|
|
|
|
mov eax, [esi + APIC_ISR + edx]
|
2011-09-21 01:11:22 +04:00
|
|
|
.nxt:
|
2012-03-08 19:49:27 +04:00
|
|
|
shr eax, 1
|
2013-09-14 22:55:13 +04:00
|
|
|
jnc @f
|
2012-03-08 12:33:38 +04:00
|
|
|
mov dword [esi + APIC_EOI], 0; EOI
|
2011-09-21 01:11:22 +04:00
|
|
|
@@:
|
2012-03-08 19:49:27 +04:00
|
|
|
loop .nxt
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 19:49:27 +04:00
|
|
|
add edx, 0x10
|
|
|
|
cmp edx, 0x170
|
|
|
|
jbe .nxt2
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Spurious-Interrupt Vector Register initialization.
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, [esi + APIC_SVR]
|
|
|
|
or eax, 0x1ff
|
|
|
|
and eax, 0xfffffdff
|
|
|
|
mov [esi + APIC_SVR], eax
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Initialize LVT LINT0 register. (INTR)
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, 0x00700
|
2011-09-21 01:11:22 +04:00
|
|
|
; mov eax, 0x10700
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [esi + APIC_LVT_LINT0], eax
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Initialize LVT LINT1 register. (NMI)
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, 0x00400
|
|
|
|
mov [esi + APIC_LVT_LINT1], eax
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; Initialize LVT Error register.
|
2012-03-08 19:49:27 +04:00
|
|
|
mov eax, [esi + APIC_LVT_err]
|
2012-03-08 12:33:38 +04:00
|
|
|
or eax, 0x10000; bit 16
|
2012-03-08 19:49:27 +04:00
|
|
|
mov [esi + APIC_LVT_err], eax
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2013-09-14 22:55:13 +04:00
|
|
|
; LAPIC timer
|
|
|
|
; pre init
|
|
|
|
mov dword[esi + APIC_timer_div], 1011b; 1
|
|
|
|
mov dword[esi + APIC_timer_init], 0xffffffff; max val
|
|
|
|
push esi
|
|
|
|
mov esi, 640 ; wait 0.64 sec
|
|
|
|
call delay_ms
|
|
|
|
pop esi
|
|
|
|
mov eax, [esi + APIC_timer_cur]; read current tick couner
|
|
|
|
xor eax, 0xffffffff ; eax = 0xffffffff - eax
|
|
|
|
shr eax, 6 ; eax /= 64; APIC ticks per 0.01 sec
|
|
|
|
|
|
|
|
; Start (every 0.01 sec)
|
|
|
|
mov dword[esi + APIC_LVT_timer], 0x30020; periodic int 0x20
|
|
|
|
mov dword[esi + APIC_timer_init], eax
|
2012-03-08 19:49:27 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
.done:
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2011-07-22 22:08:47 +04:00
|
|
|
|
2010-10-02 00:49:29 +04:00
|
|
|
;===========================================================
|
|
|
|
; IOAPIC implementation
|
|
|
|
align 4
|
|
|
|
IOAPIC_read:
|
|
|
|
; in : EAX - IOAPIC register
|
|
|
|
; out: EAX - readed value
|
2012-03-09 12:20:02 +04:00
|
|
|
push esi
|
|
|
|
mov esi, [IOAPIC_base]
|
|
|
|
mov [esi], eax
|
|
|
|
mov eax, [esi + 0x10]
|
|
|
|
pop esi
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
|
|
|
|
2010-10-02 00:49:29 +04:00
|
|
|
align 4
|
|
|
|
IOAPIC_write:
|
2013-09-14 22:55:13 +04:00
|
|
|
; in : EAX - IOAPIC register
|
|
|
|
; EBX - value
|
|
|
|
; out: none
|
2012-03-09 12:20:02 +04:00
|
|
|
push esi
|
|
|
|
mov esi, [IOAPIC_base]
|
|
|
|
mov [esi], eax
|
|
|
|
mov [esi + 0x10], ebx
|
|
|
|
pop esi
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
;===========================================================
|
|
|
|
; Remap all IRQ to 0x20+ Vectors
|
|
|
|
; IRQ0 to vector 0x20, IRQ1 to vector 0x21....
|
2011-09-21 17:58:48 +04:00
|
|
|
align 4
|
2010-10-02 00:49:29 +04:00
|
|
|
PIC_init:
|
2011-09-21 01:11:22 +04:00
|
|
|
cli
|
2012-03-08 12:33:38 +04:00
|
|
|
mov al, 0x11 ; icw4, edge triggered
|
|
|
|
out 0x20, al
|
|
|
|
out 0xA0, al
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov al, 0x20 ; generate 0x20 +
|
|
|
|
out 0x21, al
|
|
|
|
mov al, 0x28 ; generate 0x28 +
|
|
|
|
out 0xA1, al
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov al, 0x04 ; slave at irq2
|
|
|
|
out 0x21, al
|
|
|
|
mov al, 0x02 ; at irq9
|
|
|
|
out 0xA1, al
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-08 12:33:38 +04:00
|
|
|
mov al, 0x01 ; 8086 mode
|
|
|
|
out 0x21, al
|
|
|
|
out 0xA1, al
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
call IRQ_mask_all
|
2013-09-14 22:55:13 +04:00
|
|
|
; mov dword[irq_type_to_set], IRQ_TYPE_PIC
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
|
|
|
|
; -----------------------------------------
|
|
|
|
; TIMER SET TO 1/100 S
|
2011-09-21 17:58:48 +04:00
|
|
|
align 4
|
2010-10-02 00:49:29 +04:00
|
|
|
PIT_init:
|
2012-03-08 12:33:38 +04:00
|
|
|
mov al, 0x34 ; set to 100Hz
|
|
|
|
out 0x43, al
|
|
|
|
mov al, 0x9b ; lsb 1193180 / 1193
|
|
|
|
out 0x40, al
|
|
|
|
mov al, 0x2e ; msb
|
|
|
|
out 0x40, al
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
|
|
|
|
; -----------------------------------------
|
2011-09-21 17:58:48 +04:00
|
|
|
align 4
|
2010-10-02 00:49:29 +04:00
|
|
|
unmask_timer:
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp [irq_mode], IRQ_APIC
|
|
|
|
je @f
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2011-09-21 01:11:22 +04:00
|
|
|
stdcall enable_irq, 0
|
|
|
|
ret
|
2011-08-16 00:34:55 +04:00
|
|
|
@@:
|
2013-09-14 22:55:13 +04:00
|
|
|
; use PIT
|
|
|
|
; in some systems PIT no connected to IOAPIC
|
|
|
|
; mov eax, 0x14
|
|
|
|
; call IOAPIC_read
|
|
|
|
; mov ah, 0x09 ; Delivery Mode: Lowest Priority, Destination Mode: Logical
|
|
|
|
; mov al, 0x20
|
|
|
|
; or eax, 0x10000 ; Mask Interrupt
|
|
|
|
; mov ebx, eax
|
|
|
|
; mov eax, 0x14
|
|
|
|
; call IOAPIC_write
|
|
|
|
; stdcall enable_irq, 2
|
|
|
|
; ret
|
|
|
|
|
|
|
|
; use LAPIC timer
|
2012-03-09 12:20:02 +04:00
|
|
|
mov esi, [LAPIC_BASE]
|
|
|
|
mov eax, [esi + APIC_LVT_timer]
|
|
|
|
and eax, 0xfffeffff
|
|
|
|
mov [esi + APIC_LVT_timer], eax
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
|
|
|
|
; -----------------------------------------
|
|
|
|
; Disable all IRQ
|
2011-09-21 17:58:48 +04:00
|
|
|
align 4
|
2010-10-02 00:49:29 +04:00
|
|
|
IRQ_mask_all:
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp [irq_mode], IRQ_APIC
|
|
|
|
je .APIC
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov al, 0xFF
|
|
|
|
out 0x21, al
|
|
|
|
out 0xA1, al
|
2012-03-08 12:33:38 +04:00
|
|
|
mov ecx, 0x1000
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
.APIC:
|
2012-03-09 12:20:02 +04:00
|
|
|
mov ecx, [IRQ_COUNT]
|
|
|
|
mov eax, 0x10
|
2011-09-21 01:11:22 +04:00
|
|
|
@@:
|
2012-03-09 12:20:02 +04:00
|
|
|
mov ebx, eax
|
|
|
|
call IOAPIC_read
|
2012-03-08 12:33:38 +04:00
|
|
|
or eax, 0x10000; bit 16
|
2012-03-09 12:20:02 +04:00
|
|
|
xchg eax, ebx
|
|
|
|
call IOAPIC_write
|
|
|
|
inc eax
|
|
|
|
inc eax
|
|
|
|
loop @b
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
|
|
|
|
2010-10-02 00:49:29 +04:00
|
|
|
; -----------------------------------------
|
|
|
|
; End Of Interrupt
|
2011-09-10 14:52:59 +04:00
|
|
|
; cl - IRQ number
|
2011-09-21 17:58:48 +04:00
|
|
|
align 4
|
2011-09-10 14:52:59 +04:00
|
|
|
irq_eoi: ; __fastcall
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp [irq_mode], IRQ_APIC
|
|
|
|
je .APIC
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp cl, 8
|
|
|
|
mov al, 0x20
|
|
|
|
jb @f
|
|
|
|
out 0xa0, al
|
2011-09-10 14:52:59 +04:00
|
|
|
@@:
|
2012-03-09 12:20:02 +04:00
|
|
|
out 0x20, al
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2011-09-10 14:52:59 +04:00
|
|
|
|
2011-08-16 00:34:55 +04:00
|
|
|
.APIC:
|
2012-03-09 12:20:02 +04:00
|
|
|
mov eax, [LAPIC_BASE]
|
2012-03-08 12:33:38 +04:00
|
|
|
mov dword [eax + APIC_EOI], 0; EOI
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2011-08-16 00:34:55 +04:00
|
|
|
|
2010-10-02 00:49:29 +04:00
|
|
|
; -----------------------------------------
|
|
|
|
; from dll.inc
|
|
|
|
align 4
|
|
|
|
proc enable_irq stdcall, irq_line:dword
|
2012-03-09 12:20:02 +04:00
|
|
|
mov ebx, [irq_line]
|
|
|
|
cmp [irq_mode], IRQ_APIC
|
|
|
|
je .APIC
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov edx, 0x21
|
|
|
|
cmp ebx, 8
|
|
|
|
jb @F
|
2011-09-21 01:11:22 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov edx, 0xA1
|
2012-03-08 12:33:38 +04:00
|
|
|
sub ebx, 8
|
2010-10-02 00:49:29 +04:00
|
|
|
@@:
|
2012-03-08 12:33:38 +04:00
|
|
|
in al, dx
|
2012-03-09 12:20:02 +04:00
|
|
|
btr eax, ebx
|
|
|
|
out dx, al
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
.APIC:
|
2012-03-09 12:20:02 +04:00
|
|
|
shl ebx, 1
|
|
|
|
add ebx, 0x10
|
|
|
|
mov eax, ebx
|
|
|
|
call IOAPIC_read
|
2012-03-08 12:33:38 +04:00
|
|
|
and eax, 0xfffeffff; bit 16
|
2012-03-09 12:20:02 +04:00
|
|
|
xchg eax, ebx
|
|
|
|
call IOAPIC_write
|
2011-09-21 01:11:22 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
endp
|
|
|
|
|
2013-05-11 16:38:27 +04:00
|
|
|
proc disable_irq stdcall, irq_line:dword
|
|
|
|
mov ebx, [irq_line]
|
|
|
|
cmp [irq_mode], IRQ_APIC
|
|
|
|
je .APIC
|
|
|
|
|
|
|
|
mov edx, 0x21
|
|
|
|
cmp ebx, 8
|
|
|
|
jb @F
|
|
|
|
|
|
|
|
mov edx, 0xA1
|
|
|
|
sub ebx, 8
|
|
|
|
@@:
|
|
|
|
in al, dx
|
|
|
|
bts eax, ebx
|
|
|
|
out dx, al
|
|
|
|
ret
|
|
|
|
.APIC:
|
|
|
|
shl ebx, 1
|
|
|
|
add ebx, 0x10
|
|
|
|
mov eax, ebx
|
|
|
|
call IOAPIC_read
|
|
|
|
or eax, 0x10000; bit 16
|
|
|
|
xchg eax, ebx
|
|
|
|
call IOAPIC_write
|
|
|
|
ret
|
|
|
|
endp
|
|
|
|
|
2011-09-21 17:58:48 +04:00
|
|
|
align 4
|
|
|
|
pci_irq_fixup:
|
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
push ebp
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov esi, [acpi_dev_data]
|
|
|
|
mov ebx, [acpi_dev_size]
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
lea edi, [esi+ebx]
|
2011-09-21 17:58:48 +04:00
|
|
|
|
|
|
|
.iterate:
|
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp esi, edi
|
|
|
|
jae .done
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov eax, [esi]
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp eax, -1
|
|
|
|
je .done
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
movzx ebx, al
|
|
|
|
movzx ebp, ah
|
2011-09-21 17:58:48 +04:00
|
|
|
|
|
|
|
stdcall pci_read32, ebp, ebx, 0
|
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
cmp eax, [esi+4]
|
|
|
|
jne .skip
|
2011-09-21 17:58:48 +04:00
|
|
|
|
2012-03-09 12:20:02 +04:00
|
|
|
mov eax, [esi+8]
|
2011-09-21 17:58:48 +04:00
|
|
|
stdcall pci_write8, ebp, ebx, 0x3C, eax
|
|
|
|
.skip:
|
2012-03-09 12:20:02 +04:00
|
|
|
add esi, 16
|
|
|
|
jmp .iterate
|
2011-09-21 17:58:48 +04:00
|
|
|
|
|
|
|
.done:
|
|
|
|
.fail:
|
2013-09-14 22:55:13 +04:00
|
|
|
pop ebp
|
2012-03-09 12:20:02 +04:00
|
|
|
ret
|
2010-10-02 00:49:29 +04:00
|
|
|
|
2015-07-30 16:04:35 +03:00
|
|
|
align 4
|
|
|
|
get_clock_ns:
|
|
|
|
push ebx
|
|
|
|
pushfd
|
|
|
|
cli
|
2013-05-11 16:38:27 +04:00
|
|
|
|
2015-07-30 16:04:35 +03:00
|
|
|
mov ebx, [hpet_base]
|
|
|
|
@@:
|
|
|
|
mov edx, [ebx+0xF4]
|
|
|
|
mov eax, [ebx+0xF0]
|
|
|
|
mov ecx, [ebx+0xF4]
|
|
|
|
cmp ecx, edx
|
|
|
|
jnz @B
|
|
|
|
|
|
|
|
mov ecx, [hpet_period]
|
|
|
|
mov ebx, edx
|
|
|
|
imul ebx, ecx
|
|
|
|
mul ecx
|
|
|
|
add edx, ebx
|
|
|
|
|
|
|
|
popfd
|
|
|
|
pop ebx
|
|
|
|
ret
|
2011-08-16 00:34:55 +04:00
|
|
|
|