Skip to content

Commit

Permalink
Lecture 76 - Creating the ability to create and execute kernel commands
Browse files Browse the repository at this point in the history
  • Loading branch information
nibblebits committed Nov 19, 2020
1 parent ee37a5a commit 4ed3ccb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
#define USER_DATA_SEGMENT 0x23
#define USER_CODE_SEGMENT 0x1b

#define PEACHOS_MAX_ISR80H_COMMANDS 1024

#endif
37 changes: 36 additions & 1 deletion src/idt/idt.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
#include "config.h"
#include "kernel.h"
#include "memory/memory.h"
#include "task/task.h"
#include "io/io.h"
struct idt_desc idt_descriptors[PEACHOS_TOTAL_INTERRUPTS];
struct idtr_desc idtr_descriptor;

static ISR80H_COMMAND isr80h_commands[PEACHOS_MAX_ISR80H_COMMANDS];

extern void idt_load(struct idtr_desc* ptr);
extern void int21h();
extern void no_interrupt();
extern void isr80h_wrapper();

void int21h_handler()
{
Expand Down Expand Up @@ -49,15 +53,46 @@ void idt_init()

idt_set(0, idt_zero);
idt_set(0x21, int21h);
idt_set(0x80, isr80h_wrapper);


// Load the interrupt descriptor table
idt_load(&idtr_descriptor);
}

void isr80h_handle_command(int command, struct interrupt_frame* frame)
void isr80h_register_command(int command_id, ISR80H_COMMAND command)
{
if (command_id <= 0 || command_id >= PEACHOS_MAX_ISR80H_COMMANDS)
{
panic("The command is out of bounds\n");
}

if (isr80h_commands[command_id])
{
panic("Your attempting to overwrite an existing command\n");
}

isr80h_commands[command_id] = command;
}

void* isr80h_handle_command(int command, struct interrupt_frame* frame)
{
void* result = 0;

if(command <= 0 || command >= PEACHOS_MAX_ISR80H_COMMANDS)
{
// Invalid command
return 0;
}

ISR80H_COMMAND command_func = isr80h_commands[command];
if (!command_func)
{
return 0;
}

result = command_func(frame);
return result;
}

void* isr80h_handler(int command, struct interrupt_frame* frame)
Expand Down
5 changes: 5 additions & 0 deletions src/idt/idt.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#define IDT_H

#include <stdint.h>

struct interrupt_frame;
typedef void*(*ISR80H_COMMAND)(struct interrupt_frame* frame);

struct idt_desc
{
uint16_t offset_1; // Offset bits 0 - 15
Expand Down Expand Up @@ -37,5 +41,6 @@ struct interrupt_frame
void idt_init();
void enable_interrupts();
void disable_interrupts();
void isr80h_register_command(int command_id, ISR80H_COMMAND command);

#endif

0 comments on commit 4ed3ccb

Please sign in to comment.