trying to fix the drivers and also the isr, gdt and isr header files.

This commit is contained in:
Gregory Kenneth Bowne 2023-07-15 14:25:31 -07:00
parent d98d2d4292
commit 3c103367d0
9 changed files with 166 additions and 30 deletions

View File

View File

View File

@ -1,27 +1,63 @@
#include "screen.h" #include "screen.h"
#include <dos.h>
void screen_init() { #include <stdbool.h>
// Initialize the screen driver #include <stddef.h>
// Add any necessary initialization code here #include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Video memory address
#define VIDEO_MEMORY_ADDRESS 0xB8000
// Screen attributes (color)
static uint8_t screen_color =
(SCREEN_COLOR_LIGHT_GRAY << 4) | SCREEN_COLOR_BLACK;
// Helper function to calculate the screen buffer offset
static inline uint16_t screen_offset(uint8_t x, uint8_t y)
{
return (y * SCREEN_WIDTH + x) * 2;
} }
void set_40_column_mode() { // Initialize the screen driver
// Set the screen mode to 40 columns void screen_init()
union REGS regs; {
regs.h.ah = 0x00; // No initialization required for this simple driver
regs.h.al = 0x03;
int86(0x10, &regs, &regs);
} }
void set_80_column_mode() { // Clear the screen
// Set the screen mode to 80 columns void screen_clear()
union REGS regs; {
regs.h.ah = 0x00; uint16_t *video_memory = (uint16_t *)VIDEO_MEMORY_ADDRESS;
regs.h.al = 0x03; for (int i = 0; i < SCREEN_WIDTH * SCREEN_HEIGHT; i++)
int86(0x10, &regs, &regs); {
video_memory[i] = ' ' | (screen_color << 8);
regs.h.ah = 0x00; }
regs.h.al = 0x07; }
int86(0x10, &regs, &regs);
// Set the foreground and background colors
void screen_set_color(uint8_t foreground, uint8_t background)
{
screen_color = (background << 4) | foreground;
}
// Print a character at the specified position
void screen_put_char(char c, uint8_t x, uint8_t y)
{
uint16_t *video_memory = (uint16_t *)VIDEO_MEMORY_ADDRESS;
uint16_t offset = screen_offset(x, y);
video_memory[offset] = c | (screen_color << 8);
}
// Print a null-terminated string at the specified position
void screen_put_string(const char *str, uint8_t x, uint8_t y)
{
uint16_t *video_memory = (uint16_t *)VIDEO_MEMORY_ADDRESS;
uint16_t offset = screen_offset(x, y);
while (*str)
{
video_memory[offset] = *str | (screen_color << 8);
str++;
offset += 2;
}
} }

View File

@ -1,13 +1,47 @@
#ifndef SCREEN_H #ifndef SCREEN_H
#define SCREEN_H #define SCREEN_H
// Function to initialize the screen driver #include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// Screen dimensions
#define SCREEN_WIDTH 80
#define SCREEN_HEIGHT 25
// Screen colors
#define SCREEN_COLOR_BLACK 0
#define SCREEN_COLOR_BLUE 1
#define SCREEN_COLOR_GREEN 2
#define SCREEN_COLOR_CYAN 3
#define SCREEN_COLOR_RED 4
#define SCREEN_COLOR_MAGENTA 5
#define SCREEN_COLOR_BROWN 6
#define SCREEN_COLOR_LIGHT_GRAY 7
#define SCREEN_COLOR_DARK_GRAY 8
#define SCREEN_COLOR_LIGHT_BLUE 9
#define SCREEN_COLOR_LIGHT_GREEN 10
#define SCREEN_COLOR_LIGHT_CYAN 11
#define SCREEN_COLOR_LIGHT_RED 12
#define SCREEN_COLOR_LIGHT_MAGENTA 13
#define SCREEN_COLOR_YELLOW 14
#define SCREEN_COLOR_WHITE 15
// Initialize the screen driver
void screen_init(); void screen_init();
// Function to set the screen mode to 40 columns // Clear the screen
void set_40_column_mode(); void screen_clear();
// Function to set the screen mode to 80 columns // Set the foreground and background colors
void set_80_column_mode(); void screen_set_color(uint8_t foreground, uint8_t background);
// Print a character at the specified position
void screen_put_char(char c, uint8_t x, uint8_t y);
// Print a null-terminated string at the specified position
void screen_put_string(const char *str, uint8_t x, uint8_t y);
#endif #endif

36
src/drivers/tty/tty.c Normal file
View File

@ -0,0 +1,36 @@
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "../display.h"
#include "../interrupts.h"
#include "../io/io.h"
#include "../keyboard.h"
#include "../string.h"
#include "./screen/screen.h"
#include "./tty.h"
// Function definitions
// Example function to print a message to the console
void tty_print(const char *message)
{
printf("%s", message);
}
// Example function to read input from the console
void tty_read(char *buffer, size_t size)
{
fgets(buffer, size, stdin);
}
// Example function to clear the console
void tty_clear()
{
printf("\033[2J\033[H");
}
// More function definitions...

12
src/drivers/tty/tty.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef TTY_H
#define TTY_H
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
// Function declarations
#endif // TTY_H

View File

@ -1,10 +1,21 @@
#include "gdt.h" #include "gdt.h"
#include "isr.h"
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <inttypes.h>
// GDT table // GDT table
struct gdt_entry gdt[3]; struct gdt_entry *gdt;
// GDT pointer // GDT pointer
struct gdt_ptr gp; struct gdt_ptr {
uint16_t limit;
void* base;
} gp;
// Initialize a GDT entry // Initialize a GDT entry
void gdt_set_gate(uint32_t num, uint32_t base, uint32_t limit, uint8_t access, void gdt_set_gate(uint32_t num, uint32_t base, uint32_t limit, uint8_t access,
@ -24,10 +35,11 @@ void gdt_init()
{ {
// Set up GDT pointer // Set up GDT pointer
gp.limit = (sizeof(struct gdt_entry) * 3) - 1; gp.limit = (sizeof(struct gdt_entry) * 3) - 1;
gp.base = (uint32_t)&gdt; gdt = (struct gdt_entry*)malloc(sizeof(struct gdt_entry) * 3);
gp.base = gdt;
// Clear GDT // Clear GDT
memset(&gdt, 0, sizeof(gdt)); memset(gdt, 0, sizeof(struct gdt_entry) * 3);
// Set up code segment // Set up code segment
gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF); gdt_set_gate(1, 0, 0xFFFFFFFF, 0x9A, 0xCF);
@ -36,7 +48,7 @@ void gdt_init()
gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF); gdt_set_gate(2, 0, 0xFFFFFFFF, 0x92, 0xCF);
// Load GDT // Load GDT
_asm volatile("lgdt %0" : : "m"(gp)); asm volatile("lgdt %0" : : "m"(gp));
} }
// Exception handlers // Exception handlers

View File

@ -1,6 +1,12 @@
#include "idt.h" #include "idt.h"
#include <string.h> #include <string.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
// IDT table // IDT table
struct idt_entry idt[256]; struct idt_entry idt[256];

View File

@ -16,7 +16,7 @@ struct isr_regs
}; };
// Register an ISR // Register an ISR
void isr_register(uint8_t num, void (*handler)(struct isr_regs *regs)); void isr_register(uint8_t num, void (*handler)(void));
// ISR handler // ISR handler
void isr_handler(struct isr_regs *regs); void isr_handler(struct isr_regs *regs);