egnjqerhiuw3hruı3wwerfwe
This commit is contained in:
parent
74c403595d
commit
a4bcf4fe28
2
Makefile
2
Makefile
|
@ -22,7 +22,7 @@ ARCHDIR = arch/$(ARCH)/
|
|||
all: $(BIN)
|
||||
|
||||
run: $(ISO)
|
||||
$(QEMU) -d int -cdrom $(ISO)
|
||||
$(QEMU) -cdrom $(ISO)
|
||||
|
||||
$(ISO): $(BIN)
|
||||
grub-mkrescue -o $(ISO) sysroot
|
||||
|
|
|
@ -106,67 +106,7 @@ __attribute__((interrupt)) void isr18(struct interrupt_frame* frame) {
|
|||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr19(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr20(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr21(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr22(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr23(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr24(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr25(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr26(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr27(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr28(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr29(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr30(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
||||
__attribute__((interrupt)) void isr31(struct interrupt_frame* frame) {
|
||||
__attribute__((interrupt)) void isr_reserved(struct interrupt_frame* frame) {
|
||||
terminal_writeline("Reserved");
|
||||
asm("hlt");
|
||||
}
|
||||
|
@ -191,20 +131,19 @@ void isr_install(void) {
|
|||
idt_register_handler(16, (unsigned long)isr16);
|
||||
idt_register_handler(17, (unsigned long)isr17);
|
||||
idt_register_handler(18, (unsigned long)isr18);
|
||||
idt_register_handler(19, (unsigned long)isr19);
|
||||
idt_register_handler(20, (unsigned long)isr20);
|
||||
idt_register_handler(21, (unsigned long)isr21);
|
||||
idt_register_handler(22, (unsigned long)isr22);
|
||||
idt_register_handler(23, (unsigned long)isr23);
|
||||
idt_register_handler(24, (unsigned long)isr24);
|
||||
idt_register_handler(25, (unsigned long)isr25);
|
||||
idt_register_handler(26, (unsigned long)isr26);
|
||||
idt_register_handler(27, (unsigned long)isr27);
|
||||
idt_register_handler(28, (unsigned long)isr28);
|
||||
idt_register_handler(29, (unsigned long)isr29);
|
||||
idt_register_handler(30, (unsigned long)isr30);
|
||||
idt_register_handler(31, (unsigned long)isr31);
|
||||
//idt_register_handler(32, (unsigned long)isr32);
|
||||
idt_register_handler(19, (unsigned long)isr_reserved);
|
||||
idt_register_handler(20, (unsigned long)isr_reserved);
|
||||
idt_register_handler(21, (unsigned long)isr_reserved);
|
||||
idt_register_handler(22, (unsigned long)isr_reserved);
|
||||
idt_register_handler(23, (unsigned long)isr_reserved);
|
||||
idt_register_handler(24, (unsigned long)isr_reserved);
|
||||
idt_register_handler(25, (unsigned long)isr_reserved);
|
||||
idt_register_handler(26, (unsigned long)isr_reserved);
|
||||
idt_register_handler(27, (unsigned long)isr_reserved);
|
||||
idt_register_handler(28, (unsigned long)isr_reserved);
|
||||
idt_register_handler(29, (unsigned long)isr_reserved);
|
||||
idt_register_handler(30, (unsigned long)isr_reserved);
|
||||
idt_register_handler(31, (unsigned long)isr_reserved);
|
||||
|
||||
idt_init();
|
||||
}
|
|
@ -18,7 +18,7 @@ void kernel_main() {
|
|||
terminal_initialize();
|
||||
terminal_writeline("Initializing terminal... done");
|
||||
terminal_writestring("Preparing interrupts... ");
|
||||
i686_pic_init();
|
||||
pic_init();
|
||||
isr_install();
|
||||
terminal_writeline("done");
|
||||
terminal_writestring("Preparing keyboard... ");
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <keyboard.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
unsigned char kbdus[128] =
|
||||
{
|
||||
unsigned char kbdus[128] = {
|
||||
0, 27, '1', '2', '3', '4', '5', '6', '7', '8', /* 9 */
|
||||
'9', '0', '-', '=', '\b', /* Backspace */
|
||||
'\t', /* Tab */
|
||||
|
@ -46,21 +46,38 @@ uint8_t __kbd_enabled = 0;
|
|||
__attribute__((interrupt)) void keyboard_irq(struct interrupt_frame* frame) {
|
||||
unsigned char scancode = inportb(0x60);
|
||||
|
||||
const char key = kbdus[scancode];
|
||||
bool special = true;
|
||||
|
||||
switch (scancode) {
|
||||
case 72:
|
||||
terminal_row--;
|
||||
break;
|
||||
case 75:
|
||||
terminal_column--;
|
||||
break;
|
||||
case 77:
|
||||
terminal_column++;
|
||||
break;
|
||||
case 80:
|
||||
terminal_row++;
|
||||
break;
|
||||
default:
|
||||
special = false;
|
||||
}
|
||||
|
||||
if (scancode & 128) {
|
||||
// This is a release scancode, just ignore it
|
||||
i686_pic_irq_notify_on_term(1);
|
||||
pic_send_eoi(1);
|
||||
return;
|
||||
}
|
||||
|
||||
terminal_putchar(key);
|
||||
|
||||
i686_pic_irq_notify_on_term(1);
|
||||
if (!special) terminal_putchar(kbdus[scancode]);
|
||||
terminal_updatecursor();
|
||||
pic_send_eoi(1);
|
||||
}
|
||||
|
||||
void keyboard_init(void) {
|
||||
i686_pic_irq_enable(1);
|
||||
pic_irq_enable(1);
|
||||
idt_register_handler(33, (uint32_t)keyboard_irq);
|
||||
|
||||
__kbd_enabled = 1;
|
||||
|
|
|
@ -1,54 +1,38 @@
|
|||
#include <pic.h>
|
||||
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1 + 1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2 + 1)
|
||||
#define PIC_EOI 0x20
|
||||
|
||||
#define ICW1_ICW4 0x01
|
||||
#define ICW1_INIT 0x10
|
||||
#define ICW4_8086 0x01
|
||||
|
||||
static uint8_t pic1_mask = 0xff;
|
||||
static uint8_t pic2_mask = 0xff;
|
||||
|
||||
static inline void i686_cpu_io_wait() {
|
||||
asm volatile("outb %%al, $0x80" : : "a"(0));
|
||||
}
|
||||
|
||||
void i686_pic_init() {
|
||||
void pic_init() {
|
||||
outportb(PIC1_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||
i686_cpu_io_wait();
|
||||
io_wait();
|
||||
outportb(PIC2_COMMAND, ICW1_INIT | ICW1_ICW4);
|
||||
i686_cpu_io_wait();
|
||||
outportb(PIC1_DATA, 0x20);
|
||||
i686_cpu_io_wait();
|
||||
outportb(PIC2_DATA, 0x28);
|
||||
i686_cpu_io_wait();
|
||||
io_wait();
|
||||
outportb(PIC1_DATA, 0x20); // master offset 0x20
|
||||
io_wait();
|
||||
outportb(PIC2_DATA, 0x28); // slave offset 0x28
|
||||
io_wait();
|
||||
outportb(PIC1_DATA, 4);
|
||||
i686_cpu_io_wait();
|
||||
io_wait();
|
||||
outportb(PIC2_DATA, 2);
|
||||
i686_cpu_io_wait();
|
||||
io_wait();
|
||||
outportb(PIC1_DATA, ICW4_8086);
|
||||
i686_cpu_io_wait();
|
||||
io_wait();
|
||||
outportb(PIC2_DATA, ICW4_8086);
|
||||
i686_cpu_io_wait();
|
||||
io_wait();
|
||||
outportb(PIC1_DATA, pic1_mask);
|
||||
outportb(PIC2_DATA, pic2_mask);
|
||||
i686_pic_irq_enable(2);
|
||||
pic_irq_enable(2);
|
||||
}
|
||||
|
||||
void i686_pic_irq_notify_on_term(uint8_t no) {
|
||||
void pic_send_eoi(uint8_t no) {
|
||||
if (no >= 8) {
|
||||
outportb(PIC2_COMMAND, PIC_EOI);
|
||||
}
|
||||
outportb(PIC1_COMMAND, PIC_EOI);
|
||||
}
|
||||
|
||||
void i686_pic_irq_enable(uint8_t no) {
|
||||
void pic_irq_enable(uint8_t no) {
|
||||
if (no >= 8) {
|
||||
no -= 8;
|
||||
pic2_mask &= ~(1 << no);
|
||||
|
@ -59,7 +43,7 @@ void i686_pic_irq_enable(uint8_t no) {
|
|||
}
|
||||
}
|
||||
|
||||
void i686_pic_irq_disable(uint8_t no) {
|
||||
void pic_irq_disable(uint8_t no) {
|
||||
if (no >= 8) {
|
||||
no -= 8;
|
||||
pic2_mask |= (1 << no);
|
||||
|
|
|
@ -76,6 +76,17 @@ void terminal_putentryat(char c, uint8_t color, size_t x, size_t y) {
|
|||
|
||||
void terminal_putchar(char c) {
|
||||
switch (c) {
|
||||
case '\b':
|
||||
if (--terminal_column < 0) {
|
||||
if (terminal_row-- > 0) {
|
||||
terminal_column = VGA_WIDTH - 1;
|
||||
terminal_putentryat(' ', terminal_color, terminal_column, terminal_row);
|
||||
}
|
||||
} else {
|
||||
terminal_putentryat(' ', terminal_color, terminal_column, terminal_row);
|
||||
}
|
||||
terminal_updatecursor();
|
||||
return;
|
||||
case '\r':
|
||||
terminal_column = 0;
|
||||
break;
|
||||
|
|
|
@ -38,11 +38,8 @@ static inline uint32_t inportl(uint16_t const port) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
static inline void io_wait(void) {
|
||||
/* TODO: This is probably fragile. */
|
||||
asm volatile ( "jmp 1f\n\t"
|
||||
"1:jmp 2f\n\t"
|
||||
"2:" );
|
||||
static inline void io_wait() {
|
||||
asm volatile("outb %%al, $0x80" : : "a"(0));
|
||||
}
|
||||
|
||||
static inline bool are_interrupts_enabled() {
|
||||
|
|
|
@ -7,13 +7,25 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void i686_pic_init();
|
||||
void i686_pic_irq_notify_on_term(uint8_t no);
|
||||
void i686_pic_irq_enable(uint8_t no);
|
||||
void i686_pic_irq_disable(uint8_t no);
|
||||
#define PIC1 0x20
|
||||
#define PIC2 0xA0
|
||||
#define PIC1_COMMAND PIC1
|
||||
#define PIC1_DATA (PIC1 + 1)
|
||||
#define PIC2_COMMAND PIC2
|
||||
#define PIC2_DATA (PIC2 + 1)
|
||||
#define PIC_EOI 0x20
|
||||
|
||||
#define ICW1_ICW4 0x01
|
||||
#define ICW1_INIT 0x10
|
||||
#define ICW4_8086 0x01
|
||||
|
||||
void pic_init();
|
||||
void pic_send_eoi(uint8_t no);
|
||||
void pic_irq_enable(uint8_t no);
|
||||
void pic_irq_disable(uint8_t no);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _ISR_H */
|
||||
#endif /* _PIC_H */
|
Loading…
Reference in a new issue