wip: pic. sending to continue on main pc

This commit is contained in:
Karina
2025-12-27 17:09:14 +04:00
parent 144ac4e581
commit 18b3e9cbe7
8 changed files with 65 additions and 14 deletions
+2
View File
@@ -12,6 +12,8 @@ add_executable(kernel
src/entry.asm
src/asm/interrupts.asm
src/kmain.c
src/modules/io.c
src/modules/pic.c
src/modules/gdt.c
src/modules/idt.c
src/modules/interrupts.c
+7
View File
@@ -1,3 +1,6 @@
#ifndef IO_H
#define IO_H
static inline void outb(unsigned short port, unsigned char val) {
__asm__ volatile(
"outb %0, %1"
@@ -16,3 +19,7 @@ static inline unsigned char inb(unsigned short port) {
return ret;
}
void io_wait();
#endif
+4
View File
@@ -0,0 +1,4 @@
#ifndef PIC_H
#define PIC_H
#endif
-1
View File
@@ -19,7 +19,6 @@
#define PTE_GET_ADDR(entry) ((entry) & PTE_ADDR_MASK) // get physical address
#define PTE_GET_FLAGS(entry) ((entry) & ~PTE_ADDR_MASK) // get flags
#define VMM_PT_INDEX(virt) (((virt) >> 12) & 0x1FF) // Table Index (bits 12-20)
#define VMM_PD_INDEX(virt) (((virt) >> 21) & 0x1FF) // Page Directory Index (bits 21-29)
#define VMM_PDPT_INDEX(virt) (((virt) >> 30) & 0x1FF) // PDPT Index (bits 30-38)
+7
View File
@@ -0,0 +1,7 @@
#include "io.h"
// sending junk to unused port letting cpu skipping few tacts.
// not ideal i know.
void io_wait() {
outb(0x80, 0x0);
}
+32
View File
@@ -0,0 +1,32 @@
#include "pic.h"
#include "io.h"
#include "types.h"
#define MASTER_COMMAND 0x20
#define MASTER_DATA 0x21
#define SLAVE_COMMAND 0xA0
#define SLAVE_DATA 0xA1
static inline void send(unsigned short port, unsigned char val) {
outb(port, val);
io_wait();
}
void pic_remap() {
u64 curr_master = inb(MASTER_DATA);
u64 curr_slave = inb(SLAVE_DATA);
// initialization
send(MASTER_COMMAND, 0x11);
send(SLAVE_COMMAND, 0x11);
send(MASTER_DATA, 0x20); // master now controlling idt[32..39]
send(SLAVE_DATA, 0x28); // idt[40..47]
send(MASTER_DATA, 0x04); // slave on irq2
send(SLAVE_DATA, 0x02); // assign id = 2 to slave
}