forked from KolibriOS/kolibrios
map_io_mem: set proper region size
git-svn-id: svn://kolibrios.org@2217 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
8ec96e9db0
commit
9447e850cf
@ -42,6 +42,7 @@ IOAPIC_VER equ 0x1
|
|||||||
IOAPIC_ARB equ 0x2
|
IOAPIC_ARB equ 0x2
|
||||||
IOAPIC_REDTBL equ 0x10
|
IOAPIC_REDTBL equ 0x10
|
||||||
|
|
||||||
|
align 4
|
||||||
APIC_init:
|
APIC_init:
|
||||||
mov dword[APIC], 0
|
mov dword[APIC], 0
|
||||||
|
|
||||||
@ -62,6 +63,7 @@ APIC_init:
|
|||||||
movzx eax, al
|
movzx eax, al
|
||||||
cmp al, IRQ_RESERVED
|
cmp al, IRQ_RESERVED
|
||||||
jbe @f
|
jbe @f
|
||||||
|
|
||||||
mov al, IRQ_RESERVED
|
mov al, IRQ_RESERVED
|
||||||
@@:
|
@@:
|
||||||
mov [IRQ_COUNT], eax
|
mov [IRQ_COUNT], eax
|
||||||
@ -69,7 +71,8 @@ APIC_init:
|
|||||||
; Reroute IOAPIC & mask all interrupts
|
; Reroute IOAPIC & mask all interrupts
|
||||||
xor ecx, ecx
|
xor ecx, ecx
|
||||||
mov eax, IOAPIC_REDTBL
|
mov eax, IOAPIC_REDTBL
|
||||||
@@: mov ebx, eax
|
@@:
|
||||||
|
mov ebx, eax
|
||||||
call IOAPIC_read
|
call IOAPIC_read
|
||||||
mov ah, 0x09 ; Delivery Mode: Lowest Priority, Destination Mode: Logical
|
mov ah, 0x09 ; Delivery Mode: Lowest Priority, Destination Mode: Logical
|
||||||
mov al, cl
|
mov al, cl
|
||||||
@ -77,6 +80,7 @@ APIC_init:
|
|||||||
or eax, 0x10000 ; Mask Interrupt
|
or eax, 0x10000 ; Mask Interrupt
|
||||||
cmp ecx, 16
|
cmp ecx, 16
|
||||||
jb .set
|
jb .set
|
||||||
|
|
||||||
or eax, 0xa000 ;<<< level-triggered active-low for IRQ16+
|
or eax, 0xa000 ;<<< level-triggered active-low for IRQ16+
|
||||||
.set:
|
.set:
|
||||||
xchg eax, ebx
|
xchg eax, ebx
|
||||||
@ -103,6 +107,8 @@ APIC_init:
|
|||||||
|
|
||||||
; mov dword[irq_type_to_set], IRQ_TYPE_APIC
|
; mov dword[irq_type_to_set], IRQ_TYPE_APIC
|
||||||
|
|
||||||
|
.no_apic:
|
||||||
|
|
||||||
;init handlers table
|
;init handlers table
|
||||||
|
|
||||||
mov ecx, IRQ_RESERVED
|
mov ecx, IRQ_RESERVED
|
||||||
@ -116,7 +122,6 @@ APIC_init:
|
|||||||
mov ecx, 47
|
mov ecx, 47
|
||||||
mov eax, irqh_pool+IRQH.sizeof
|
mov eax, irqh_pool+IRQH.sizeof
|
||||||
mov [next_irqh], irqh_pool
|
mov [next_irqh], irqh_pool
|
||||||
|
|
||||||
@@:
|
@@:
|
||||||
mov [eax-IRQH.sizeof], eax
|
mov [eax-IRQH.sizeof], eax
|
||||||
add eax, IRQH.sizeof
|
add eax, IRQH.sizeof
|
||||||
@ -124,7 +129,6 @@ APIC_init:
|
|||||||
|
|
||||||
mov [eax-IRQH.sizeof], dword 0
|
mov [eax-IRQH.sizeof], dword 0
|
||||||
|
|
||||||
.no_apic:
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;===========================================================
|
;===========================================================
|
||||||
@ -146,7 +150,6 @@ LAPIC_init:
|
|||||||
or eax, 0xf0000000
|
or eax, 0xf0000000
|
||||||
mov [esi + APIC_DFR], eax
|
mov [esi + APIC_DFR], eax
|
||||||
|
|
||||||
|
|
||||||
; Program Logical Destination Register.
|
; Program Logical Destination Register.
|
||||||
mov eax, [esi + APIC_LDR]
|
mov eax, [esi + APIC_LDR]
|
||||||
;and eax, 0xff000000
|
;and eax, 0xff000000
|
||||||
@ -161,12 +164,16 @@ LAPIC_init:
|
|||||||
|
|
||||||
; Flush the queue
|
; Flush the queue
|
||||||
mov edx, 0
|
mov edx, 0
|
||||||
.nxt2: mov ecx, 32
|
.nxt2:
|
||||||
|
mov ecx, 32
|
||||||
mov eax, [esi + APIC_ISR + edx]
|
mov eax, [esi + APIC_ISR + edx]
|
||||||
.nxt: shr eax, 1
|
.nxt:
|
||||||
|
shr eax, 1
|
||||||
jnc @f
|
jnc @f
|
||||||
mov dword [esi + APIC_EOI], 0 ; EOI
|
mov dword [esi + APIC_EOI], 0 ; EOI
|
||||||
@@: loop .nxt
|
@@:
|
||||||
|
loop .nxt
|
||||||
|
|
||||||
add edx, 0x10
|
add edx, 0x10
|
||||||
cmp edx, 0x170
|
cmp edx, 0x170
|
||||||
jbe .nxt2
|
jbe .nxt2
|
||||||
@ -206,8 +213,8 @@ LAPIC_init:
|
|||||||
; Start (every 0.01 sec)
|
; Start (every 0.01 sec)
|
||||||
mov dword[esi + APIC_LVT_timer], 0x30020 ; periodic int 0x20
|
mov dword[esi + APIC_LVT_timer], 0x30020 ; periodic int 0x20
|
||||||
mov dword[esi + APIC_timer_init], eax
|
mov dword[esi + APIC_timer_init], eax
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
;===========================================================
|
;===========================================================
|
||||||
; IOAPIC implementation
|
; IOAPIC implementation
|
||||||
align 4
|
align 4
|
||||||
@ -220,6 +227,7 @@ IOAPIC_read:
|
|||||||
mov eax, [esi + 0x10]
|
mov eax, [esi + 0x10]
|
||||||
pop esi
|
pop esi
|
||||||
ret
|
ret
|
||||||
|
|
||||||
align 4
|
align 4
|
||||||
IOAPIC_write:
|
IOAPIC_write:
|
||||||
; in : EAX - IOAPIC register
|
; in : EAX - IOAPIC register
|
||||||
@ -238,40 +246,26 @@ PIC_init:
|
|||||||
cli
|
cli
|
||||||
mov al,0x11 ; icw4, edge triggered
|
mov al,0x11 ; icw4, edge triggered
|
||||||
out 0x20,al
|
out 0x20,al
|
||||||
call pic_delay
|
|
||||||
out 0xA0,al
|
out 0xA0,al
|
||||||
call pic_delay
|
|
||||||
|
|
||||||
mov al,0x20 ; generate 0x20 +
|
mov al,0x20 ; generate 0x20 +
|
||||||
out 0x21,al
|
out 0x21,al
|
||||||
call pic_delay
|
|
||||||
mov al,0x28 ; generate 0x28 +
|
mov al,0x28 ; generate 0x28 +
|
||||||
out 0xA1,al
|
out 0xA1,al
|
||||||
call pic_delay
|
|
||||||
|
|
||||||
mov al,0x04 ; slave at irq2
|
mov al,0x04 ; slave at irq2
|
||||||
out 0x21,al
|
out 0x21,al
|
||||||
call pic_delay
|
|
||||||
mov al,0x02 ; at irq9
|
mov al,0x02 ; at irq9
|
||||||
out 0xA1,al
|
out 0xA1,al
|
||||||
call pic_delay
|
|
||||||
|
|
||||||
mov al,0x01 ; 8086 mode
|
mov al,0x01 ; 8086 mode
|
||||||
out 0x21,al
|
out 0x21,al
|
||||||
call pic_delay
|
|
||||||
out 0xA1,al
|
out 0xA1,al
|
||||||
call pic_delay
|
|
||||||
|
|
||||||
call IRQ_mask_all
|
call IRQ_mask_all
|
||||||
cli
|
|
||||||
; mov dword[irq_type_to_set], IRQ_TYPE_PIC
|
; mov dword[irq_type_to_set], IRQ_TYPE_PIC
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; -----------------------------------------
|
|
||||||
pic_delay:
|
|
||||||
jmp pdl1
|
|
||||||
pdl1: ret
|
|
||||||
|
|
||||||
; -----------------------------------------
|
; -----------------------------------------
|
||||||
; TIMER SET TO 1/100 S
|
; TIMER SET TO 1/100 S
|
||||||
PIT_init:
|
PIT_init:
|
||||||
@ -319,14 +313,12 @@ IRQ_mask_all:
|
|||||||
out 0x21, al
|
out 0x21, al
|
||||||
out 0xA1, al
|
out 0xA1, al
|
||||||
mov ecx,0x1000
|
mov ecx,0x1000
|
||||||
cld
|
|
||||||
@@: call pic_delay
|
|
||||||
loop @b
|
|
||||||
ret
|
ret
|
||||||
.APIC:
|
.APIC:
|
||||||
mov ecx, [IRQ_COUNT]
|
mov ecx, [IRQ_COUNT]
|
||||||
mov eax, 0x10
|
mov eax, 0x10
|
||||||
@@: mov ebx, eax
|
@@:
|
||||||
|
mov ebx, eax
|
||||||
call IOAPIC_read
|
call IOAPIC_read
|
||||||
or eax, 0x10000 ; bit 16
|
or eax, 0x10000 ; bit 16
|
||||||
xchg eax, ebx
|
xchg eax, ebx
|
||||||
@ -335,6 +327,7 @@ IRQ_mask_all:
|
|||||||
inc eax
|
inc eax
|
||||||
loop @b
|
loop @b
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; -----------------------------------------
|
; -----------------------------------------
|
||||||
; End Of Interrupt
|
; End Of Interrupt
|
||||||
; cl - IRQ number
|
; cl - IRQ number
|
||||||
@ -342,6 +335,7 @@ align 16
|
|||||||
irq_eoi: ; __fastcall
|
irq_eoi: ; __fastcall
|
||||||
test dword[APIC], 0xffffffff
|
test dword[APIC], 0xffffffff
|
||||||
jnz .APIC
|
jnz .APIC
|
||||||
|
|
||||||
cmp cl, 8
|
cmp cl, 8
|
||||||
mov al, 0x20
|
mov al, 0x20
|
||||||
jb @f
|
jb @f
|
||||||
@ -362,9 +356,11 @@ proc enable_irq stdcall, irq_line:dword
|
|||||||
mov ebx, [irq_line]
|
mov ebx, [irq_line]
|
||||||
test dword[APIC], 0xffffffff
|
test dword[APIC], 0xffffffff
|
||||||
jnz .APIC
|
jnz .APIC
|
||||||
|
|
||||||
mov edx, 0x21
|
mov edx, 0x21
|
||||||
cmp ebx, 8
|
cmp ebx, 8
|
||||||
jb @F
|
jb @F
|
||||||
|
|
||||||
mov edx, 0xA1
|
mov edx, 0xA1
|
||||||
sub ebx,8
|
sub ebx,8
|
||||||
@@:
|
@@:
|
||||||
|
@ -171,9 +171,14 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword
|
|||||||
push ebx
|
push ebx
|
||||||
push edi
|
push edi
|
||||||
mov eax, [size]
|
mov eax, [size]
|
||||||
|
add eax, [base]
|
||||||
add eax, 4095
|
add eax, 4095
|
||||||
and eax, -4096
|
and eax, -4096
|
||||||
|
mov ecx, [base]
|
||||||
|
and ecx, -4096
|
||||||
|
sub eax, ecx
|
||||||
mov [size], eax
|
mov [size], eax
|
||||||
|
|
||||||
stdcall alloc_kernel_space, eax
|
stdcall alloc_kernel_space, eax
|
||||||
test eax, eax
|
test eax, eax
|
||||||
jz .fail
|
jz .fail
|
||||||
@ -189,9 +194,7 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword
|
|||||||
or edx, [flags]
|
or edx, [flags]
|
||||||
@@:
|
@@:
|
||||||
mov [page_tabs+eax*4], edx
|
mov [page_tabs+eax*4], edx
|
||||||
; push eax
|
|
||||||
invlpg [ebx]
|
invlpg [ebx]
|
||||||
; pop eax
|
|
||||||
inc eax
|
inc eax
|
||||||
add ebx, edi
|
add ebx, edi
|
||||||
add edx, edi
|
add edx, edi
|
||||||
|
Loading…
Reference in New Issue
Block a user