feat(pic): add simple pic initialization
Signed-off-by: Julien CLEMENT <julien.clement@epita.fr>
This commit is contained in:
parent
51107d84c8
commit
46e8386bbf
@ -33,7 +33,8 @@ OBJS = \
|
||||
serial.o \
|
||||
gdt.o \
|
||||
idt.o \
|
||||
isr.o
|
||||
isr.o \
|
||||
pic.o
|
||||
|
||||
|
||||
DEPS = $(OBJS:.o=.d)
|
||||
|
4
k/idt.c
4
k/idt.c
@ -35,7 +35,9 @@ static struct idt_entry_descriptor idt_entries_descriptors[IDT_NB_ENTRIES] = {
|
||||
{0, {0, 0, 0}, 0}, // 28
|
||||
{0, {0, 0, 0}, 0}, // 29
|
||||
{0, {0, 0, 0}, 0}, // 30
|
||||
{0, {0, 0, 0}, 0} // 31
|
||||
{0, {0, 0, 0}, 0}, // 31
|
||||
{0, {0, 0, 0}, 0}, // 32
|
||||
{(uint32_t)&isr_keyboard, KERNEL_CS_SEGMENT_SELECTOR, INTERRUPT_TYPE}, // 33
|
||||
};
|
||||
|
||||
void interrupt_handler(struct isr_param *isr_param)
|
||||
|
3
k/idt.h
3
k/idt.h
@ -5,7 +5,8 @@
|
||||
#include "gdt.h"
|
||||
#include "isr.h"
|
||||
|
||||
#define IDT_NB_ENTRIES 32
|
||||
#define IDT_RESERVED_ENTRIES 32
|
||||
#define IDT_NB_ENTRIES 34
|
||||
#define IDT_SIZE (IDT_NB_ENTRIES * sizeof(struct idt_entry))
|
||||
|
||||
#define INTERRUPT_TYPE 0x6
|
||||
|
1
k/isr.S
1
k/isr.S
@ -44,3 +44,4 @@ isr_callback_no_error(isr_machine_check, 18)
|
||||
isr_callback_no_error(isr_simd_floating_point_exception, 19)
|
||||
isr_callback_no_error(isr_virtualization_exception, 20)
|
||||
isr_callback_error(isr_control_protection_exception, 21)
|
||||
isr_callback_no_error(isr_keyboard, 33)
|
||||
|
1
k/isr.h
1
k/isr.h
@ -28,5 +28,6 @@ void isr_machine_check(void);
|
||||
void isr_simd_floating_point_exception(void);
|
||||
void isr_virtualization_exception(void);
|
||||
void isr_control_protection_exception(void);
|
||||
void isr_keyboard(void);
|
||||
|
||||
#endif /* !ISR_H */
|
||||
|
2
k/k.c
2
k/k.c
@ -26,6 +26,7 @@
|
||||
#include "gdt.h"
|
||||
#include "idt.h"
|
||||
#include "multiboot.h"
|
||||
#include "pic.h"
|
||||
#include "serial.h"
|
||||
#include "stdio.h"
|
||||
|
||||
@ -34,6 +35,7 @@ static void k_init(void)
|
||||
init_serial();
|
||||
init_gdt();
|
||||
init_idt();
|
||||
init_pic();
|
||||
}
|
||||
|
||||
void k_main(unsigned long magic, multiboot_info_t *info)
|
||||
|
44
k/pic.c
Normal file
44
k/pic.c
Normal file
@ -0,0 +1,44 @@
|
||||
#include "idt.h"
|
||||
#include "io.h"
|
||||
#include "pic.h"
|
||||
|
||||
static void send_icw1(void)
|
||||
{
|
||||
outb(MASTER_PIC_A, ICW1);
|
||||
outb(SLAVE_PIC_A, ICW1);
|
||||
}
|
||||
|
||||
static void send_icw2(void)
|
||||
{
|
||||
outb(MASTER_PIC_B, IDT_RESERVED_ENTRIES);
|
||||
outb(SLAVE_PIC_B, IDT_RESERVED_ENTRIES + 8);
|
||||
}
|
||||
|
||||
static void send_icw3(void)
|
||||
{
|
||||
outb(MASTER_PIC_B, 0x4);
|
||||
outb(SLAVE_PIC_B, 0x2);
|
||||
}
|
||||
|
||||
|
||||
static void send_icw4(void)
|
||||
{
|
||||
outb(MASTER_PIC_B, 0x1);
|
||||
outb(SLAVE_PIC_B, 0x1);
|
||||
}
|
||||
|
||||
static void mask_irqs(void)
|
||||
{
|
||||
outb(MASTER_PIC_B, 0xff);
|
||||
outb(SLAVE_PIC_B, 0xff);
|
||||
}
|
||||
|
||||
void init_pic(void)
|
||||
{
|
||||
send_icw1();
|
||||
send_icw2();
|
||||
send_icw3();
|
||||
send_icw4();
|
||||
mask_irqs();
|
||||
asm volatile("sti");
|
||||
}
|
13
k/pic.h
Normal file
13
k/pic.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef PIC_H
|
||||
#define PIC_H
|
||||
|
||||
#define MASTER_PIC_A 0x20
|
||||
#define MASTER_PIC_B 0x21
|
||||
#define SLAVE_PIC_A 0xa0
|
||||
#define SLAVE_PIC_B 0xa1
|
||||
|
||||
#define ICW1 0x11
|
||||
|
||||
void init_pic(void);
|
||||
|
||||
#endif /* !PIC_H */
|
Loading…
Reference in New Issue
Block a user