mirror of
https://github.com/gbowne1/ClassicOS.git
synced 2026-03-09 08:25:19 -07:00
Compare commits
2 Commits
gbowne1-ad
...
gbowne1-ad
| Author | SHA1 | Date | |
|---|---|---|---|
| 95372a66e6 | |||
| e376526426 |
25
kernel/pic.h
Normal file
25
kernel/pic.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef PIC_H
|
||||
#define PIC_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* I/O Ports for the PICs */
|
||||
#define PIC1_COMMAND 0x20
|
||||
#define PIC1_DATA 0x21
|
||||
#define PIC2_COMMAND 0xA0
|
||||
#define PIC2_DATA 0xA1
|
||||
|
||||
/* PIC Commands */
|
||||
#define PIC_EOI 0x20 /* End of Interrupt */
|
||||
|
||||
/* Offset vectors for remapping */
|
||||
#define PIC1_OFFSET 0x20
|
||||
#define PIC2_OFFSET 0x28
|
||||
|
||||
void pic_init(void);
|
||||
void pic_send_eoi(uint8_t irq);
|
||||
void pic_mask(uint8_t irq);
|
||||
void pic_unmask(uint8_t irq);
|
||||
void pic_disable(void);
|
||||
|
||||
#endif
|
||||
19
kernel/vfs.c
19
kernel/vfs.c
@@ -1,19 +0,0 @@
|
||||
#include "vfs.h"
|
||||
#include "kmalloc.h"
|
||||
#include "string_utils.h"
|
||||
|
||||
vfs_node_t* vfs_root = NULL;
|
||||
|
||||
uint32_t vfs_read(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buffer) {
|
||||
if (node->read != NULL) {
|
||||
return node->read(node, offset, size, buffer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
vfs_node_t* vfs_finddir(vfs_node_t* node, const char* name) {
|
||||
if ((node->flags & VFS_DIRECTORY) && node->finddir != NULL) {
|
||||
return node->finddir(node, name);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
42
kernel/vfs.h
42
kernel/vfs.h
@@ -1,42 +0,0 @@
|
||||
#ifndef VFS_H
|
||||
#define VFS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
struct vfs_node;
|
||||
|
||||
// Function pointers that every FS driver must provide
|
||||
typedef uint32_t (*vfs_read_func)(struct vfs_node*, uint32_t, uint32_t, uint8_t*);
|
||||
typedef struct vfs_node* (*vfs_finddir_func)(struct vfs_node*, const char* name);
|
||||
|
||||
typedef struct vfs_node {
|
||||
char name[128];
|
||||
uint32_t mask; // Permissions
|
||||
uint32_t uid; // User ID
|
||||
uint32_t gid; // Group ID
|
||||
uint32_t flags; // Node type (File, Directory, etc.)
|
||||
uint32_t inode; // FS-specific identifier
|
||||
uint32_t length; // Size in bytes
|
||||
|
||||
// Function table
|
||||
vfs_read_func read;
|
||||
vfs_finddir_func finddir;
|
||||
|
||||
struct vfs_node* ptr; // Used for mountpoints or symlinks
|
||||
} vfs_node_t;
|
||||
|
||||
// Standard node types
|
||||
#define VFS_FILE 0x01
|
||||
#define VFS_DIRECTORY 0x02
|
||||
#define VFS_MOUNTPOINT 0x04
|
||||
|
||||
// The root of the filesystem (/)
|
||||
extern vfs_node_t* vfs_root;
|
||||
|
||||
// Public API
|
||||
uint32_t vfs_read(vfs_node_t* node, uint32_t offset, uint32_t size, uint8_t* buffer);
|
||||
vfs_node_t* vfs_finddir(vfs_node_t* node, const char* name);
|
||||
|
||||
#endif
|
||||
76
pic.c
Normal file
76
pic.c
Normal file
@@ -0,0 +1,76 @@
|
||||
#include "pic.h"
|
||||
#include "io.h"
|
||||
|
||||
/* Small delay for older hardware bus timing */
|
||||
static inline void io_wait(void) {
|
||||
outb(0x80, 0);
|
||||
}
|
||||
|
||||
void pic_init(void) {
|
||||
uint8_t a1, a2;
|
||||
|
||||
// Save current masks
|
||||
a1 = inb(PIC1_DATA);
|
||||
a2 = inb(PIC2_DATA);
|
||||
|
||||
// ICW1: Start initialization in cascade mode
|
||||
outb(PIC1_COMMAND, 0x11);
|
||||
io_wait();
|
||||
outb(PIC2_COMMAND, 0x11);
|
||||
io_wait();
|
||||
|
||||
// ICW2: Master PIC vector offset
|
||||
outb(PIC1_DATA, PIC1_OFFSET);
|
||||
io_wait();
|
||||
// ICW2: Slave PIC vector offset
|
||||
outb(PIC2_DATA, PIC2_OFFSET);
|
||||
io_wait();
|
||||
|
||||
// ICW3: Tell Master there is a slave at IRQ2 (0000 0100)
|
||||
outb(PIC1_DATA, 4);
|
||||
io_wait();
|
||||
// ICW3: Tell Slave its cascade identity (0000 0010)
|
||||
outb(PIC2_DATA, 2);
|
||||
io_wait();
|
||||
|
||||
// ICW4: Set 8086/88 mode
|
||||
outb(PIC1_DATA, 0x01);
|
||||
io_wait();
|
||||
outb(PIC2_DATA, 0x01);
|
||||
io_wait();
|
||||
|
||||
// Restore masks (or disable all to start clean)
|
||||
outb(PIC1_DATA, 0xFB); // Keep IRQ2 (cascade) open
|
||||
outb(PIC2_DATA, 0xFF);
|
||||
}
|
||||
|
||||
void pic_send_eoi(uint8_t irq) {
|
||||
if (irq >= 8) {
|
||||
outb(PIC2_COMMAND, PIC_EOI);
|
||||
}
|
||||
outb(PIC1_COMMAND, PIC_EOI);
|
||||
}
|
||||
|
||||
void pic_unmask(uint8_t irq) {
|
||||
uint16_t port;
|
||||
if (irq < 8) {
|
||||
port = PIC1_DATA;
|
||||
} else {
|
||||
port = PIC2_DATA;
|
||||
irq -= 8;
|
||||
}
|
||||
uint8_t value = inb(port) & ~(1 << irq);
|
||||
outb(port, value);
|
||||
}
|
||||
|
||||
void pic_mask(uint8_t irq) {
|
||||
uint16_t port;
|
||||
if (irq < 8) {
|
||||
port = PIC1_DATA;
|
||||
} else {
|
||||
port = PIC2_DATA;
|
||||
irq -= 8;
|
||||
}
|
||||
uint8_t value = inb(port) | (1 << irq);
|
||||
outb(port, value);
|
||||
}
|
||||
Reference in New Issue
Block a user