fixed the CMakeLists.txt so that it includes all the files in source as variables

This commit is contained in:
2023-09-17 12:37:26 -07:00
parent c4749319be
commit 0a638989fa
46 changed files with 1123 additions and 509 deletions

View File

@@ -1,7 +1,7 @@
#include "io.h"
/*
Common Ports
Common Ports
COM1: 0x3F8
COM2: 0x2F8
COM3: 0x3E8
@@ -24,6 +24,12 @@ char io_read_com()
// TODO: Read from the COM port
// Use the appropriate memory or I/O address to read from the port
// Return the read data
char data = 0; // Initialize the variable to store the read data
// Read from the COM port and assign the read value to the 'data' variable
return data; // Return the read data
}
// Function to write to the COM port
@@ -40,6 +46,12 @@ char io_read_lpt()
// TODO: Read from the LPT port
// Use the appropriate memory or I/O address to read from the port
// Return the read data
char data = 0; // Initialize the variable to store the read data
// Read from the LPT port and assign the read value to the 'data' variable
return data; // Return the read data
}
// Function to write to the LPT port

View File

@@ -1,6 +1,8 @@
#ifndef IO_H
#define IO_H
#include <stdint.h>
// Function to initialize the COM and LPT ports
void io_init();
@@ -16,4 +18,9 @@ char io_read_lpt();
// Function to write to the LPT port
void io_write_lpt(char data);
// Function declarations for keyboard.c
uint8_t inb(uint16_t port);
void outb(uint16_t port, uint8_t data);
void install_interrupt_handler(uint8_t interrupt, void (*handler)(void));
#endif /* IO_H */

View File

@@ -1,46 +1,56 @@
#include <stdint.h>
#include "keyboard.h"
#include "../io/io.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
// Keyboard input buffer
#define KEYBOARD_BUFFER_SIZE 32
static uint8_t keyboard_buffer[KEYBOARD_BUFFER_SIZE];
static size_t keyboard_buffer_head = 0;
static size_t keyboard_buffer_tail = 0;
static size_t keyboard_buffer_head = 0;
static size_t keyboard_buffer_tail = 0;
// Keyboard interrupt handler
void keyboard_interrupt_handler() {
uint8_t scancode = inb(0x60);
void keyboard_interrupt_handler()
{
uint8_t scancode = inb(0x60);
// Add scancode to buffer
keyboard_buffer[keyboard_buffer_head] = scancode;
keyboard_buffer_head = (keyboard_buffer_head + 1) % KEYBOARD_BUFFER_SIZE;
// Add scancode to buffer
keyboard_buffer[keyboard_buffer_head] = scancode;
keyboard_buffer_head = (keyboard_buffer_head + 1) % KEYBOARD_BUFFER_SIZE;
}
// Initialize keyboard
void keyboard_init() {
// Install keyboard interrupt handler
install_interrupt_handler(0x09, keyboard_interrupt_handler);
void keyboard_init()
{
// Install keyboard interrupt handler
set_interrupt_vector(0x09, keyboard_interrupt_handler);
enable_interrupt(0x09);
// Enable keyboard
outb(0x64, 0xAE);
while (inb(0x64) & 0x02);
outb(0x60, 0xF4);
while (inb(0x60) != 0xFA);
// Enable keyboard
outb(0x64, 0xAE);
while (inb(0x64) & 0x02)
;
outb(0x60, 0xF4);
while (inb(0x60) != 0xFA)
;
}
// Check if keyboard buffer is empty
bool keyboard_buffer_empty() {
return keyboard_buffer_head == keyboard_buffer_tail;
bool keyboard_buffer_empty()
{
return keyboard_buffer_head == keyboard_buffer_tail;
}
// Read scancode from keyboard buffer
uint8_t keyboard_read_scancode() {
if (keyboard_buffer_empty()) {
return 0;
}
uint8_t keyboard_read_scancode()
{
if (keyboard_buffer_empty())
{
return 0;
}
uint8_t scancode = keyboard_buffer[keyboard_buffer_tail];
keyboard_buffer_tail = (keyboard_buffer_tail + 1) % KEYBOARD_BUFFER_SIZE;
return scancode;
uint8_t scancode = keyboard_buffer[keyboard_buffer_tail];
keyboard_buffer_tail = (keyboard_buffer_tail + 1) % KEYBOARD_BUFFER_SIZE;
return scancode;
}

View File

@@ -2,6 +2,12 @@
#include "idt.h"
#include <stdio.h>
#define TIMER_INTERRUPT 0x20
#define KEYBOARD_INTERRUPT 0x21
#define NETWORK_INTERRUPT 0x22
#define DISK_INTERRUPT 0x23
#define SERIAL_PORT_INTERRUPT 0x24
// ISR table
void (*isr_table[256])(struct isr_regs *regs);
@@ -18,6 +24,14 @@ void isr_handler(struct isr_regs *regs)
{
divide_error();
}
else if (regs->int_no == 13)
{
general_protection_fault(regs);
}
else if (regs->int_no == 14)
{
page_fault(regs);
}
else
{
void (*handler)(struct isr_regs *regs);
@@ -36,14 +50,31 @@ void divide_error()
printf("Divide by zero error!\n");
}
void page_fault()
void page_fault(struct isr_regs *regs)
{
// Handle page fault exception
uint32_t faulting_address;
// Read the CR2 register to get the faulting address
asm volatile("mov %%cr2, %0" : "=r"(faulting_address));
// Print an error message with the faulting address
printf("Page fault at 0x%x, virtual address 0x%x\n", regs->eip,
faulting_address);
// Halt the system
for (;;)
;
}
void general_protection_fault()
void general_protection_fault(struct isr_regs *regs)
{
// Handle general protection fault exception
// Handle the general protection fault exception
printf("General protection fault occurred!\n");
// Additional actions can be taken as needed
// Halt the system
for (;;)
;
}
void double_fault()
@@ -52,9 +83,37 @@ void double_fault()
}
// Interrupt handlers
void system_call()
void system_call(struct isr_regs *regs)
{
// Handle system call interrupt
// Get the system call number from the eax register
uint32_t syscall_number = regs->eax;
// Handle different system call numbers
switch (syscall_number)
{
case 1:
// Handle open() system call
// ...
break;
case 2:
// Handle read() system call
// ...
break;
case 3:
// Handle write() system call
// ...
break;
case 4:
// Handle close() system call
// ...
break;
// Add more cases for other system calls
default:
// Unknown system call number
printf("Unknown system call number: %d\n", syscall_number);
break;
}
}
void timer()
@@ -69,5 +128,32 @@ void keyboard()
void device()
{
// Handle device interrupt
// Determine the type of device interrupt
uint32_t interrupt_type = /* Read the interrupt type from the device */;
// Call the appropriate interrupt handler
switch (interrupt_type)
{
case TIMER_INTERRUPT:
timer();
break;
case KEYBOARD_INTERRUPT:
keyboard();
break;
case NETWORK_INTERRUPT:
network();
break;
case DISK_INTERRUPT:
disk();
break;
case SERIAL_PORT_INTERRUPT:
serial_port();
break;
// Add more cases for other types of device interrupts
default:
// Unknown interrupt type
printf("Unknown device interrupt type: %d\n", interrupt_type);
break;
}
}

0
src/kernel/interrupts Normal file
View File

View File

@@ -1,5 +1,7 @@
#include "kernel.h"
#include <stdio.h>
void print_string(const char* str) {
// Your code to print the string to the screen goes here
void print_string(const char *str)
{
printf("%s", str);
}