map_io_mem: set proper region size

git-svn-id: svn://kolibrios.org@2217 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2011-09-20 21:11:22 +00:00
parent 8ec96e9db0
commit 9447e850cf
3 changed files with 246 additions and 247 deletions

View File

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

View File

@ -171,9 +171,14 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword
push ebx
push edi
mov eax, [size]
add eax, [base]
add eax, 4095
and eax, -4096
mov ecx, [base]
and ecx, -4096
sub eax, ecx
mov [size], eax
stdcall alloc_kernel_space, eax
test eax, eax
jz .fail
@ -189,9 +194,7 @@ proc map_io_mem stdcall, base:dword, size:dword, flags:dword
or edx, [flags]
@@:
mov [page_tabs+eax*4], edx
; push eax
invlpg [ebx]
; pop eax
inc eax
add ebx, edi
add edx, edi