Interrupts are working.. processor no longer resets

This commit is contained in:
nigel 2021-05-12 20:43:15 -04:00
parent 0d0c06ab09
commit 28ac6a05af
6 changed files with 207 additions and 201 deletions

View File

@ -24,7 +24,7 @@ all: clean build
build: build_kernel run
run:
$(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio
$(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std
build_kernel: $(OBJ_LINK_LIST)

View File

@ -138,7 +138,6 @@ irq12:
.globl irq13
irq13:
cli
push $0
push $13
jmp irq_common
@ -269,117 +268,6 @@ irq31:
jmp irq_common
.globl irq0
irq0:
cli
push $0
push $0
jmp irq_common
.globl irq1
irq1:
cli
push $0
push $1
jmp irq_common
.globl irq2
irq2:
cli
push $0
push $2
jmp irq_common
.globl irq3
irq3:
cli
push $0
push $3
jmp irq_common
.globl irq4
irq4:
cli
push $0
push $4
jmp irq_common
.globl irq5
irq5:
cli
push $0
push $5
jmp irq_common
.globl irq6
irq6:
cli
push $0
push $6
jmp irq_common
.globl irq7
irq7:
cli
push $0
push $7
jmp irq_common
.globl irq8
irq8:
cli
push $0
push $8
jmp irq_common
.globl irq9
irq9:
cli
push $0
push $9
jmp irq_common
.globl irq10
irq10:
cli
push $0
push $10
jmp irq_common
.globl irq11
irq11:
cli
push $0
push $11
jmp irq_common
.globl irq12
irq12:
cli
push $0
push $12
jmp irq_common
.globl irq13
irq13:
cli
push $0
push $13
jmp irq_common
.globl irq14
irq14:
cli
push $0
push $14
jmp irq_common
.globl irq15
irq15:
cli
push $0
push $15
jmp irq_common

View File

@ -1,5 +1,103 @@
#include "idt.h"
static void itoa (char *buf, int base, int d) {
char *p = buf;
char *p1, *p2;
unsigned long ud = d;
int divisor = 10;
if ( base == 'd' && d < 0){
*p++ = '-';
buf++;
ud = -d;
} else if (base == 'x'){
divisor = 16;
}
do {
int remainder = ud % divisor;
*p++ = (remainder < 10 ) ? remainder + '0' : remainder + 'a' -10;
} while(ud /= divisor);
/*terminate buf*/
*p =0;
p1 = buf;
p2 = p -1;
while (p1 < p2)
{
char tmp = *p1;
*p1 = *p2;
*p2 = tmp;
p1++;
p2--;
}
}
void printf ( const char *format, ...) {
AS_KERNEL();
char **arg = (char **)&format;
int c;
char buf[20];
arg++;
while ((c = *format++) != 0){
if( c != '%')
kterm_put(c);
else{
char *p, *p2;
int pad0 = 0, pad = 0;
c = *format++;
if(c =='0'){
pad0 = 1;
c = *format++;
}
if ( c >= '0' && c <= '9'){
pad = c - '0';
c = *format++;
}
switch (c)
{
case 'd':
case 'u':
case 'x':
itoa(buf, c, *((int *) arg++));
p = buf;
goto string;
break;
case 's':
p = *arg++;
if(!p)
p = "(null)";
string:
for (p2 = p; *p2; p2++);
for (; p2 < p + pad; p2++)
kterm_put(pad0 ? '0': ' ');
while (*p)
kterm_put(*p++);
break;
default:
kterm_put(*((int *)arg++));
break;
}
}
}
}
IDT_entry idt_table[256];
IDT_ptr idt_ptr;
@ -15,6 +113,15 @@ void set_id_entry (uint8_t num , uint32_t base, uint16_t sel, uint8_t flags){
void irq_handler (registers regs) {
kterm_writestring("received interrupt!\n");
printf(" Interrupt number: %d \n", regs.int_no);
if( regs.int_no == 13){
printf(" Error code: %d \n", regs.err_code);
}
}
@ -26,57 +133,57 @@ void init_idt(){
// TODO: Set everything to zero first
set_id_entry(0, (uint32_t) irs0 , 0x08, 0x8E);
set_id_entry(1, (uint32_t) irs1 , 0x08, 0x8E);
set_id_entry(2, (uint32_t) irs2 , 0x08, 0x8E);
set_id_entry(3, (uint32_t) irs3 , 0x08, 0x8E);
set_id_entry(4, (uint32_t) irs4 , 0x08, 0x8E);
set_id_entry(5, (uint32_t) irs5 , 0x08, 0x8E);
set_id_entry(6, (uint32_t) irs6 , 0x08, 0x8E);
set_id_entry(7, (uint32_t) irs7 , 0x08, 0x8E);
set_id_entry(8, (uint32_t) irs8 , 0x08, 0x8E);
set_id_entry(9, (uint32_t) irs9 , 0x08, 0x8E);
set_id_entry(10, (uint32_t) irs10 , 0x08, 0x8E);
set_id_entry(11, (uint32_t) irs11 , 0x08, 0x8E);
set_id_entry(12, (uint32_t) irs12 , 0x08, 0x8E);
set_id_entry(13, (uint32_t) irs13 , 0x08, 0x8E);
set_id_entry(14, (uint32_t) irs14 , 0x08, 0x8E);
set_id_entry(15, (uint32_t) irs15 , 0x08, 0x8E);
set_id_entry(16, (uint32_t) irs16 , 0x08, 0x8E);
set_id_entry(17, (uint32_t) irs17 , 0x08, 0x8E);
set_id_entry(18, (uint32_t) irs18 , 0x08, 0x8E);
set_id_entry(19, (uint32_t) irs19 , 0x08, 0x8E);
set_id_entry(20, (uint32_t) irs20 , 0x08, 0x8E);
set_id_entry(21, (uint32_t) irs21 , 0x08, 0x8E);
set_id_entry(22, (uint32_t) irs22 , 0x08, 0x8E);
set_id_entry(23, (uint32_t) irs23 , 0x08, 0x8E);
set_id_entry(24, (uint32_t) irs24 , 0x08, 0x8E);
set_id_entry(25, (uint32_t) irs25 , 0x08, 0x8E);
set_id_entry(26, (uint32_t) irs26 , 0x08, 0x8E);
set_id_entry(27, (uint32_t) irs27 , 0x08, 0x8E);
set_id_entry(28, (uint32_t) irs28 , 0x08, 0x8E);
set_id_entry(29, (uint32_t) irs29 , 0x08, 0x8E);
set_id_entry(30, (uint32_t) irs30 , 0x08, 0x8E);
set_id_entry(31, (uint32_t) irs31 , 0x08, 0x8E);
set_id_entry(0, (uint32_t) irq0 , 0x08, 0x8E);
set_id_entry(1, (uint32_t) irq1 , 0x08, 0x8E);
set_id_entry(2, (uint32_t) irq2 , 0x08, 0x8E);
set_id_entry(3, (uint32_t) irq3 , 0x08, 0x8E);
set_id_entry(4, (uint32_t) irq4 , 0x08, 0x8E);
set_id_entry(5, (uint32_t) irq5 , 0x08, 0x8E);
set_id_entry(6, (uint32_t) irq6 , 0x08, 0x8E);
set_id_entry(7, (uint32_t) irq7 , 0x08, 0x8E);
set_id_entry(8, (uint32_t) irq8 , 0x08, 0x8E);
set_id_entry(9, (uint32_t) irq9 , 0x08, 0x8E);
set_id_entry(10, (uint32_t) irq10 , 0x08, 0x8E);
set_id_entry(11, (uint32_t) irq11 , 0x08, 0x8E);
set_id_entry(12, (uint32_t) irq12 , 0x08, 0x8E);
set_id_entry(13, (uint32_t) irq13 , 0x08, 0x8E);
set_id_entry(14, (uint32_t) irq14 , 0x08, 0x8E);
set_id_entry(15, (uint32_t) irq15 , 0x08, 0x8E);
set_id_entry(16, (uint32_t) irq16 , 0x08, 0x8E);
set_id_entry(17, (uint32_t) irq17 , 0x08, 0x8E);
set_id_entry(18, (uint32_t) irq18 , 0x08, 0x8E);
set_id_entry(19, (uint32_t) irq19 , 0x08, 0x8E);
set_id_entry(20, (uint32_t) irq20 , 0x08, 0x8E);
set_id_entry(21, (uint32_t) irq21 , 0x08, 0x8E);
set_id_entry(22, (uint32_t) irq22 , 0x08, 0x8E);
set_id_entry(23, (uint32_t) irq23 , 0x08, 0x8E);
set_id_entry(24, (uint32_t) irq24 , 0x08, 0x8E);
set_id_entry(25, (uint32_t) irq25 , 0x08, 0x8E);
set_id_entry(26, (uint32_t) irq26 , 0x08, 0x8E);
set_id_entry(27, (uint32_t) irq27 , 0x08, 0x8E);
set_id_entry(28, (uint32_t) irq28 , 0x08, 0x8E);
set_id_entry(29, (uint32_t) irq29 , 0x08, 0x8E);
set_id_entry(30, (uint32_t) irq30 , 0x08, 0x8E);
set_id_entry(31, (uint32_t) irq31 , 0x08, 0x8E);
/*
// pic IRQ Table
set_id_entry(32, (uint32_t)irq0, 0x08, 0x8E);
set_id_entry(33, (uint32_t)irq1, 0x08, 0x8E);
set_id_entry(34, (uint32_t)irq2, 0x08, 0x8E);
set_id_entry(35, (uint32_t)irq3, 0x08, 0x8E);
set_id_entry(36, (uint32_t)irq4, 0x08, 0x8E);
set_id_entry(37, (uint32_t)irq5, 0x08, 0x8E);
set_id_entry(38, (uint32_t)irq6, 0x08, 0x8E);
set_id_entry(39, (uint32_t)irq7, 0x08, 0x8E);
set_id_entry(40, (uint32_t)irq8, 0x08, 0x8E);
set_id_entry(41, (uint32_t)irq9, 0x08, 0x8E);
set_id_entry(42, (uint32_t)irq10, 0x08, 0x8E);
set_id_entry(43, (uint32_t)irq11, 0x08, 0x8E);
set_id_entry(44, (uint32_t)irq12, 0x08, 0x8E);
set_id_entry(45, (uint32_t)irq13, 0x08, 0x8E);
set_id_entry(46, (uint32_t)irq14, 0x08, 0x8E);
set_id_entry(47, (uint32_t)irq15, 0x08, 0x8E);
set_id_entry(32, (uint32_t)irs0, 0x08, 0x8E);
set_id_entry(33, (uint32_t)irs1, 0x08, 0x8E);
set_id_entry(34, (uint32_t)irs2, 0x08, 0x8E);
set_id_entry(35, (uint32_t)irs3, 0x08, 0x8E);
set_id_entry(36, (uint32_t)irs4, 0x08, 0x8E);
set_id_entry(37, (uint32_t)irs5, 0x08, 0x8E);
set_id_entry(38, (uint32_t)irs6, 0x08, 0x8E);
set_id_entry(39, (uint32_t)irs7, 0x08, 0x8E);
set_id_entry(40, (uint32_t)irs8, 0x08, 0x8E);
set_id_entry(41, (uint32_t)irs9, 0x08, 0x8E);
set_id_entry(42, (uint32_t)irs10, 0x08, 0x8E);
set_id_entry(43, (uint32_t)irs11, 0x08, 0x8E);
set_id_entry(44, (uint32_t)irs12, 0x08, 0x8E);
set_id_entry(45, (uint32_t)irs13, 0x08, 0x8E);
set_id_entry(46, (uint32_t)irs14, 0x08, 0x8E);
set_id_entry(47, (uint32_t)irs15, 0x08, 0x8E);*/
idt_flush((uint32_t)&idt_ptr);

View File

@ -1,7 +1,14 @@
#pragma once
#include "stdint.h"
#include "stddef.h"
#include "arch/i386/vga/colors.h"
#define AS_KERNEL() ( kterm_writestring("[KERNEL]:"))
extern "C" void kterm_writestring(const char* data );
extern "C" void kterm_putat(char, uint8_t, size_t, size_t);
extern "C" void kterm_put(char);
extern "C" {
struct __attribute__((__packed__)) IDT_entry {
@ -31,39 +38,6 @@ extern "C" {
void irq_handler (registers regs);
extern void irs0 ();
extern void irs1 ();
extern void irs2 ();
extern void irs3 ();
extern void irs4 ();
extern void irs5 ();
extern void irs6 ();
extern void irs7 ();
extern void irs8 ();
extern void irs9 ();
extern void irs10 ();
extern void irs11 ();
extern void irs12 ();
extern void irs13 ();
extern void irs14 ();
extern void irs15 ();
extern void irs16 ();
extern void irs17 ();
extern void irs18 ();
extern void irs19 ();
extern void irs20 ();
extern void irs21 ();
extern void irs22 ();
extern void irs23 ();
extern void irs24 ();
extern void irs25 ();
extern void irs26 ();
extern void irs27 ();
extern void irs28 ();
extern void irs29 ();
extern void irs30 ();
extern void irs31 ();
extern void irq0 ();
extern void irq1 ();
extern void irq2 ();
@ -80,6 +54,39 @@ extern "C" {
extern void irq13 ();
extern void irq14 ();
extern void irq15 ();
extern void irq16 ();
extern void irq17 ();
extern void irq18 ();
extern void irq19 ();
extern void irq20 ();
extern void irq21 ();
extern void irq22 ();
extern void irq23 ();
extern void irq24 ();
extern void irq25 ();
extern void irq26 ();
extern void irq27 ();
extern void irq28 ();
extern void irq29 ();
extern void irq30 ();
extern void irq31 ();
/*
extern void irq0 ();
extern void irq1 ();
extern void irq2 ();
extern void irq3 ();
extern void irq4 ();
extern void irq5 ();
extern void irq6 ();
extern void irq7 ();
extern void irq8 ();
extern void irq9 ();
extern void irq10 ();
extern void irq11 ();
extern void irq12 ();
extern void irq13 ();
extern void irq14 ();
extern void irq15 ();*/

View File

@ -9,6 +9,10 @@ void delay(int t){
asm("NOP");
}
class Test {
public:
Test();
@ -109,7 +113,7 @@ extern "C" {
print_serial("Remapping PIC\n");
// remap the PIC IRQ table
outb(0x20, 0x11);
/*outb(0x20, 0x11);
outb(0xA0, 0x11);
outb(0x21, 0x20);
outb(0xA1, 0x28);
@ -118,7 +122,7 @@ extern "C" {
outb(0x21, 0x01);
outb(0xA1, 0x01);
outb(0x21, 0x0);
outb(0xA1, 0x0);
outb(0xA1, 0x0);*/
print_serial("done... \n");
@ -158,7 +162,7 @@ extern "C" {
auto testObject = Test();
testObject.printMe();
IRQ_set_mask(0);
/*IRQ_set_mask(0);
IRQ_set_mask(1);
IRQ_set_mask(2);
IRQ_set_mask(3);
@ -174,13 +178,13 @@ extern "C" {
IRQ_set_mask(13);
IRQ_set_mask(14);
IRQ_set_mask(15);
*/
/** test interrupt handlers **/
asm volatile ("int $0x03");
//asm volatile ("int $4");
asm volatile ("int $4");
/** Lets start using the serial port for debugging .. **/
// Hopefully once we go into realmode or do something that

View File

@ -6,4 +6,4 @@ extern "C" {
#include "MMU.h"
#include "io.h"
#include "idt.h"
#include "pic.h"
//#include "pic.h"