Skip to content

Commit

Permalink
pic setup code entered
Browse files Browse the repository at this point in the history
  • Loading branch information
Kazthwak committed Nov 30, 2022
1 parent 67735f6 commit 577c8c2
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 42 deletions.
40 changes: 0 additions & 40 deletions c/drivers.c
Original file line number Diff line number Diff line change
@@ -1,43 +1,3 @@
//pic stuff

//resets the pic status so it can handle more interupts again
void picintdone(unsigned char irq){
if(irq >= 8){
byteout(spiccommand,PIC_EOI);
}
else{
byteout(mpiccommand,PIC_EOI);
}}

void PIC_init(int offset1, int offset2){
unsigned char a1, a2;

a1 = bytein(mpicdata); // save masks
a2 = bytein(spicdata);

byteout(mpiccommand, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
wait(2);
byteout(spiccommand, ICW1_INIT | ICW1_ICW4);
wait(2);
byteout(mpicdata, offset1); // ICW2: Master PIC vector offset
wait(2);
byteout(spicdata, offset2); // ICW2: Slave PIC vector offset
wait(2);
byteout(mpicdata, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
wait(2);
byteout(spicdata, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
wait(2);

byteout(mpicdata, ICW4_8086);
wait(2);
byteout(spicdata, ICW4_8086);
wait(2);

byteout(mpicdata, a1); // restore saved masks.
byteout(spicdata, a2);
}


//supposed to handle scrolling but not implemented yet
void scroll(){
}
Expand Down
4 changes: 4 additions & 0 deletions c/headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
//for ifdefs for debug checking
#define debug

//includes
#include <stdint.h>


//pic controll stuff
#define mpiccommand 0x0020
#define mpicdata 0x0021
Expand Down
78 changes: 78 additions & 0 deletions c/pic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//pic stuff

//resets the pic status so it can handle more interupts again
void picintdone(unsigned char irq){
if(irq >= 8){
byteout(spiccommand,PIC_EOI);
}
else{
byteout(mpiccommand,PIC_EOI);
}}

void PIC_init(int offset1, int offset2){
unsigned char a1, a2;

a1 = bytein(mpicdata); // save masks
a2 = bytein(spicdata);

byteout(mpiccommand, ICW1_INIT | ICW1_ICW4); // starts the initialization sequence (in cascade mode)
wait(2);
byteout(spiccommand, ICW1_INIT | ICW1_ICW4);
wait(2);
byteout(mpicdata, offset1); // ICW2: Master PIC vector offset
wait(2);
byteout(spicdata, offset2); // ICW2: Slave PIC vector offset
wait(2);
byteout(mpicdata, 4); // ICW3: tell Master PIC that there is a slave PIC at IRQ2 (0000 0100)
wait(2);
byteout(spicdata, 2); // ICW3: tell Slave PIC its cascade identity (0000 0010)
wait(2);

byteout(mpicdata, ICW4_8086);
wait(2);
byteout(spicdata, ICW4_8086);
wait(2);

byteout(mpicdata, a1); // restore saved masks.
byteout(spicdata, a2);
}


void IRQ_set_mask(unsigned char IRQline) {
uint16_t port;
uint8_t value;

if(IRQline < 8) {
port = mpicdata;
} else {
port = spicdata;
IRQline -= 8;
}
value = bytein(port) | (1 << IRQline);
byteout(port, value);
}

void IRQ_clear_mask(unsigned char IRQline) {
uint16_t port;
uint8_t value;

if(IRQline < 8) {
port = mpicdata;
} else {
port = spicdata;
IRQline -= 8;
}
value = bytein(port) & ~(1 << IRQline);
byteout(port, value);
}

void EOI(int pic){
if(pic == 0){
byteout(mpiccommand, 0x20);
}else{
byteout(spiccommand, 0x20);
byteout(mpiccommand, 0x20);
}
}

//setting up idt now. def didnt copy paste the code I am offended you would even think that
5 changes: 3 additions & 2 deletions kernel_entry.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
jmp declared
declared:
jmp initidt
%include "idt.asm"
idtdone:
[bits 32] ; We ’ re in protected mode by now , so use 32 - bit instructions.
; Ensures that we jump straight into the kernel ’s entry function.
[extern main] ; Declate that we will be referencing the external symbol ’ main ’,
Expand Down
Binary file modified os-image
Binary file not shown.

0 comments on commit 577c8c2

Please sign in to comment.