From b9be2e70c1b0268c82c6dd4e6afa65c9b5ca4ff3 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Wed, 2 Sep 2020 02:32:04 +0200 Subject: [PATCH] Change PIC IRQ flushing method --- limine.bin | Bin 32768 -> 32768 bytes src/drivers/pic.c | 43 ++++++++++++++++++++++ src/drivers/pic.h | 11 ++++++ src/lib/real.c | 82 ------------------------------------------ src/lib/real.h | 2 -- src/protos/stivale.c | 4 ++- src/protos/stivale2.c | 4 ++- 7 files changed, 60 insertions(+), 86 deletions(-) create mode 100644 src/drivers/pic.c create mode 100644 src/drivers/pic.h diff --git a/limine.bin b/limine.bin index 6b707945e67e0e290648e3246b96f607e53a7c3b..5276f5f4ee27955b62069d7c0c65aacc354b9df1 100644 GIT binary patch delta 5476 zcmZ`-4OmoV_P_6CfI&tEl^GB}7?cmeFGzs^QB(#+Q3pn66e6wEy^^_FOlf6IjU*$^ zZguL}a`OXqi)t(PKayyxq7WmtrIn?wny92N4Wj0EYu*1jcLuYqo#(lC-gD0He7xs9 z=iEDEw~KbWxNU_h;mzxUVAEs|cpbmBtF{Y*;K*sjwP4d16_tlef6Uz=*nOGN8lg`=t%Rt+~*0~23Gj+{n(*`}^Bwrf9XHc8jc zqN%+D5vzD}ro9Pc0%wS9IJg2!D;+DrSPuRd(~O`bs2(?+UQzvt@OdUWlgn*F>z~j+dvx<%eFyk zNI$k6riB=Ay(A>D=XR9R=DhED0=L8FkYaITI@}0Z7XEh>Jld;=c26Ta>}0i@;He%X zGM1uS`|VQgswKEP`|ZcHs}7-ZN46*ko*493GZ9+>X?KuM@}7_?2*Oj9t-z} z=Hlv5Xgq8PO;J|!BI*z-RP^u!9-sw&964KIqQ)|D8`6%p%i;^KpkHr)*Mwt^TftAw zUGqXU(pW6GEkc~tvcsEc<;`>CkPXq6%}3mkW!mrnD=s_JPt3xWjtcCn0fVeS#~t{ zFIP(k;T>%;Yk)i2K?&+#xTxr=nv5l9;wJ`S(9PjhjTJqy5T&mmFZ?g!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svd*M0wkt^Z(rxk-$c*T0;53>^g P>RsDjSrACK64n0#l-5Rz diff --git a/src/drivers/pic.c b/src/drivers/pic.c new file mode 100644 index 00000000..7c2d7cd3 --- /dev/null +++ b/src/drivers/pic.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include +#include + +void pic_eoi(int irq) { + if (irq >= 8) { + port_out_b(0xa0, 0x20); + } + + port_out_b(0x20, 0x20); +} + +// Flush all potentially pending IRQs +void pic_flush(void) { + for (int i = 0; i < 16; i++) + pic_eoi(i); +} + +void pic_set_mask(int line, bool status) { + uint16_t port; + uint8_t value; + + if (line < 8) { + port = 0x21; + } else { + port = 0xa1; + line -= 8; + } + + if (!status) + value = port_in_b(port) & ~((uint8_t)1 << line); + else + value = port_in_b(port) | ((uint8_t)1 << line); + + port_out_b(port, value); +} + +void pic_mask_all(void) { + port_out_b(0xa1, 0xff); + port_out_b(0x21, 0xff); +} diff --git a/src/drivers/pic.h b/src/drivers/pic.h new file mode 100644 index 00000000..e4962bb6 --- /dev/null +++ b/src/drivers/pic.h @@ -0,0 +1,11 @@ +#ifndef __DRIVERS__PIT_H__ +#define __DRIVERS__PIT_H__ + +#include + +void pic_eoi(int irq); +void pic_flush(void); +void pic_set_mask(int line, bool status); +void pic_mask_all(void); + +#endif diff --git a/src/lib/real.c b/src/lib/real.c index 18270366..5e6cfe75 100644 --- a/src/lib/real.c +++ b/src/lib/real.c @@ -2,88 +2,6 @@ #include #include -__attribute__((naked)) -void rm_flush_irqs(void) { - ASM_BASIC( - // Mask PICs - "mov al, 0xff\n\t" - "out 0x21, al\n\t" - "out 0xa1, al\n\t" - - // Save GDT in case BIOS overwrites it - "sgdt [8f]\n\t" - - // Save non-scratch GPRs - "push ebx\n\t" - "push esi\n\t" - "push edi\n\t" - "push ebp\n\t" - - // Jump to real mode - FARJMP32("0x08", "1f") - "1: .code16\n\t" - "mov ax, 0x10\n\t" - "mov ds, ax\n\t" - "mov es, ax\n\t" - "mov fs, ax\n\t" - "mov gs, ax\n\t" - "mov ss, ax\n\t" - "mov eax, cr0\n\t" - "and al, 0xfe\n\t" - "mov cr0, eax\n\t" - FARJMP16("0", "1f") - "1:\n\t" - "mov ax, 0\n\t" - "mov ds, ax\n\t" - "mov es, ax\n\t" - "mov fs, ax\n\t" - "mov gs, ax\n\t" - "mov ss, ax\n\t" - - "sti\n\t" - "call 2f\n\t" // call await - "cli\n\t" - - // Restore GDT - "lgdt [8f]\n\t" - - // Jump back to pmode - "mov eax, cr0\n\t" - "or al, 1\n\t" - "mov cr0, eax\n\t" - FARJMP16("0x18", "1f") - "1: .code32\n\t" - "mov ax, 0x20\n\t" - "mov ds, ax\n\t" - "mov es, ax\n\t" - "mov fs, ax\n\t" - "mov gs, ax\n\t" - "mov ss, ax\n\t" - - // Restore non-scratch GPRs - "pop ebp\n\t" - "pop edi\n\t" - "pop esi\n\t" - "pop ebx\n\t" - - // Exit - "ret\n\t" - - // gdt - "1: .long 0\n\t" - " .long 0\n\t" - - // Await - ".code16\n\t" - "2: xor al, al\n\t" - "mov cx, 0x1000\n\t" - "3: out 0x80, al\n\t" - "loop 3b\n\t" - "ret\n\t" - ".code32\n\t" - ); -} - __attribute__((naked)) void rm_int(uint8_t int_no, struct rm_regs *out_regs, struct rm_regs *in_regs) { ASM_BASIC( diff --git a/src/lib/real.h b/src/lib/real.h index b04eb146..545cbded 100644 --- a/src/lib/real.h +++ b/src/lib/real.h @@ -24,6 +24,4 @@ struct rm_regs { void rm_int(uint8_t int_no, struct rm_regs *out_regs, struct rm_regs *in_regs); -void rm_flush_irqs(void); - #endif diff --git a/src/protos/stivale.c b/src/protos/stivale.c index d3efab14..305191be 100644 --- a/src/protos/stivale.c +++ b/src/protos/stivale.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -248,7 +249,8 @@ void stivale_load(char *cmdline, int boot_drive) { rm_int(0x15, &r, &r); } - rm_flush_irqs(); + pic_mask_all(); + pic_flush(); if (bits == 64) { void *pagemap_ptr; diff --git a/src/protos/stivale2.c b/src/protos/stivale2.c index a5bef8ec..5f812872 100644 --- a/src/protos/stivale2.c +++ b/src/protos/stivale2.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -414,7 +415,8 @@ void stivale2_load(char *cmdline, int boot_drive) { rm_int(0x15, &r, &r); } - rm_flush_irqs(); + pic_mask_all(); + pic_flush(); if (bits == 64) { void *pagemap_ptr;