add PIC code from osdev
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Define the object files
|
# Define the object files
|
||||||
OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o bin/utils.o bin/string.o bin/stdio.o bin/disk.o
|
OBJS = bin/boot.o bin/kernel.o bin/idt.o bin/isr.o bin/screen.o bin/utils.o bin/string.o bin/stdio.o bin/disk.o bin/pic.o
|
||||||
|
|
||||||
# Define the compiler and assembler
|
# Define the compiler and assembler
|
||||||
CC = gcc -D__is_katauos
|
CC = gcc -D__is_katauos
|
||||||
@@ -58,6 +58,9 @@ bin/stdio.o: src/stdio.c
|
|||||||
bin/disk.o: src/disk.c
|
bin/disk.o: src/disk.c
|
||||||
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
bin/pic.o: src/pic.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf bin/
|
rm -rf bin/
|
||||||
rm -f $(OUTPUT)
|
rm -f $(OUTPUT)
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#ifndef PIC_H
|
||||||
|
#define PIC_H
|
||||||
|
|
||||||
|
#include "../include/utils.h"
|
||||||
|
|
||||||
|
void pic_remap(int offset1, int offset2);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include "../include/utils.h"
|
#include "../include/utils.h"
|
||||||
#include "../include/disk.h"
|
#include "../include/disk.h"
|
||||||
#include "../include/string.h"
|
#include "../include/string.h"
|
||||||
|
#include "../include/pic.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ void kmain()
|
|||||||
{
|
{
|
||||||
terminal_initialize();
|
terminal_initialize();
|
||||||
printf("KatauOS booting up\n");
|
printf("KatauOS booting up\n");
|
||||||
|
pic_remap(0x20, 0x28);
|
||||||
isr_install();
|
isr_install();
|
||||||
printf("Kernel init sequence completed\n");
|
printf("Kernel init sequence completed\n");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
#include "../include/pic.h"
|
||||||
|
|
||||||
|
//took this straight outta https://wiki.osdev.org/8259_PIC#Code_Examples
|
||||||
|
|
||||||
|
#define PIC1 0x20 /* IO base address for master PIC */
|
||||||
|
#define PIC2 0xA0 /* IO base address for slave PIC */
|
||||||
|
#define PIC1_COMMAND PIC1
|
||||||
|
#define PIC1_DATA (PIC1+1)
|
||||||
|
#define PIC2_COMMAND PIC2
|
||||||
|
#define PIC2_DATA (PIC2+1)
|
||||||
|
|
||||||
|
#define PIC_EOI 0x20 /* End-of-interrupt command code */
|
||||||
|
|
||||||
|
#define PIC_READ_IRR 0x0a /* OCW3 irq ready next CMD read */
|
||||||
|
#define PIC_READ_ISR 0x0b /* OCW3 irq service next CMD read */
|
||||||
|
|
||||||
|
/* reinitialize the PIC controllers, giving them specified vector offsets
|
||||||
|
rather than 8h and 70h, as configured by default */
|
||||||
|
|
||||||
|
#define ICW1_ICW4 0x01 /* Indicates that ICW4 will be present */
|
||||||
|
#define ICW1_SINGLE 0x02 /* Single (cascade) mode */
|
||||||
|
#define ICW1_INTERVAL4 0x04 /* Call address interval 4 (8) */
|
||||||
|
#define ICW1_LEVEL 0x08 /* Level triggered (edge) mode */
|
||||||
|
#define ICW1_INIT 0x10 /* Initialization - required! */
|
||||||
|
|
||||||
|
#define ICW4_8086 0x01 /* 8086/88 (MCS-80/85) mode */
|
||||||
|
#define ICW4_AUTO 0x02 /* Auto (normal) EOI */
|
||||||
|
#define ICW4_BUF_SLAVE 0x08 /* Buffered mode/slave */
|
||||||
|
#define ICW4_BUF_MASTER 0x0C /* Buffered mode/master */
|
||||||
|
#define ICW4_SFNM 0x10 /* Special fully nested (not) */
|
||||||
|
|
||||||
|
static inline void io_wait()
|
||||||
|
{
|
||||||
|
outb(0x80, 0x00);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
arguments:
|
||||||
|
offset1 - vector offset for master PIC
|
||||||
|
vectors on the master become offset1..offset1+7
|
||||||
|
offset2 - same for slave PIC: offset2..offset2+7
|
||||||
|
*/
|
||||||
|
void pic_remap(int offset1, int offset2)
|
||||||
|
{
|
||||||
|
outb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||||
|
io_wait();
|
||||||
|
outb(PIC1_DATA, offset1); // ICW2: Master PIC vector offset
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, offset2); // ICW2: Slave PIC vector offset
|
||||||
|
io_wait();
|
||||||
|
outb(PIC1_DATA, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
outb(PIC1_DATA, ICW4_8086); // ICW4: have the PICs use 8086 mode (and not 8080 mode)
|
||||||
|
io_wait();
|
||||||
|
outb(PIC2_DATA, ICW4_8086);
|
||||||
|
io_wait();
|
||||||
|
|
||||||
|
// Unmask both PICs.
|
||||||
|
outb(PIC1_DATA, 0);
|
||||||
|
outb(PIC2_DATA, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void pic_disable(void) {
|
||||||
|
outb(PIC1_DATA, 0xff);
|
||||||
|
outb(PIC2_DATA, 0xff);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user