diff options
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | bochs.cfg | 49 | ||||
| -rw-r--r-- | drivers/include/ps2.h | 9 | ||||
| -rw-r--r-- | drivers/include/tty.h (renamed from drivers/tty.h) | 0 | ||||
| -rw-r--r-- | drivers/include/vga.h (renamed from drivers/vga.h) | 0 | ||||
| -rw-r--r-- | drivers/ps2.c | 29 | ||||
| -rw-r--r-- | drivers/tty.c | 6 | ||||
| -rw-r--r-- | kernel/include/isr.h | 11 | ||||
| -rw-r--r-- | kernel/include/panic.h | 1 | ||||
| -rw-r--r-- | kernel/include/timer.h | 7 | ||||
| -rw-r--r-- | kernel/irq.c | 4 | ||||
| -rw-r--r-- | kernel/isr.c | 2 | ||||
| -rw-r--r-- | kernel/main.c | 26 | ||||
| -rw-r--r-- | kernel/timer.c | 17 | ||||
| -rw-r--r-- | libc/stdio.c | 18 |
15 files changed, 168 insertions, 15 deletions
@@ -1,7 +1,7 @@ -OBJ = drivers/tty.o kernel/main.o boot/head.o kernel/io.o kernel/gdt-as.o kernel/gdt.o libc/stdio.o libc/string.o kernel/idt.o kernel/idt-as.o kernel/isr.o kernel/irq-as.o kernel/isr-as.o kernel/irq.o kernel/panic.o +OBJ = drivers/tty.o kernel/main.o boot/head.o kernel/io.o kernel/gdt-as.o kernel/gdt.o libc/stdio.o libc/string.o kernel/idt.o kernel/idt-as.o kernel/isr.o kernel/irq-as.o kernel/isr-as.o kernel/irq.o kernel/panic.o kernel/timer.o drivers/ps2.o CC = gcc LD = ld -INCLUDES = -Idrivers -Ikernel/include -Ilibc/include +INCLUDES = -Idrivers/include -Ikernel/include -Ilibc/include CFLAGS = -std=gnu99 -ffreestanding -fno-stack-protector -nostdlib -Wall -Wextra -m32 $(INCLUDES) -g AS = as diff --git a/bochs.cfg b/bochs.cfg new file mode 100644 index 0000000..67ab123 --- /dev/null +++ b/bochs.cfg @@ -0,0 +1,49 @@ +# configuration file generated by Bochs +plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, iodebug=1 +config_interface: textconfig +display_library: x +memory: host=32, guest=32 +romimage: file="/usr/share/bochs/BIOS-bochs-latest" +vgaromimage: file="/usr/share/bochs/VGABIOS-lgpl-latest" +boot: cdrom +floppy_bootsig_check: disabled=0 +# no floppya +# no floppyb +ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 +ata0-master: type=cdrom, path="kappa.iso", status=inserted, model="Generic 1234", biosdetect=auto +ata0-slave: type=none +ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 +ata1-master: type=none +ata1-slave: type=none +ata2: enabled=0 +ata3: enabled=0 +pci: enabled=1, chipset=i440fx +vga: extension=vbe, update_freq=5 +cpu: count=1:1:1, ips=4000000, quantum=16, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 +cpuid: level=6, stepping=3, model=3, family=6, vendor_string="AuthenticAMD", brand_string="AMD Athlon(tm) processor" +cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0 +cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, avx_f16c=0, avx_fma=0, bmi=0, xop=0, fma4=0 +cpuid: tbm=0, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0, smep=0, smap=0, mwait=1 +print_timestamps: enabled=0 +debugger_log: - +magic_break: enabled=0 +port_e9_hack: enabled=0 +private_colormap: enabled=0 +clock: sync=none, time0=local, rtc_sync=0 +# no cmosimage +# no loader +log: - +logprefix: %t%e%d +debug: action=ignore +info: action=report +error: action=report +panic: action=ask +keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none +mouse: type=ps2, enabled=0, toggle=ctrl+mbutton +speaker: enabled=1, mode=system +parport1: enabled=1, file=none +parport2: enabled=0 +com1: enabled=1, mode=null +com2: enabled=0 +com3: enabled=0 +com4: enabled=0 diff --git a/drivers/include/ps2.h b/drivers/include/ps2.h new file mode 100644 index 0000000..924ef24 --- /dev/null +++ b/drivers/include/ps2.h @@ -0,0 +1,9 @@ +#include <stdint.h> + +#define PS2_SCROLL_LOCK (1 << 0) +#define PS2_NUM_LOCK (1 << 1) +#define PS2_CAPS_LOCK (1 << 2) + +void ps2_set_leds(uint8_t status); + +void ps2_init(void); diff --git a/drivers/tty.h b/drivers/include/tty.h index 0e142c6..0e142c6 100644 --- a/drivers/tty.h +++ b/drivers/include/tty.h diff --git a/drivers/vga.h b/drivers/include/vga.h index bf13cba..bf13cba 100644 --- a/drivers/vga.h +++ b/drivers/include/vga.h diff --git a/drivers/ps2.c b/drivers/ps2.c new file mode 100644 index 0000000..ff85091 --- /dev/null +++ b/drivers/ps2.c @@ -0,0 +1,29 @@ +#include <stdint.h> +#include <stdio.h> +#include "io.h" +#include "isr.h" +#include "ps2.h" + +void ps2_set_leds(uint8_t status) +{ + outb(0x60, 0xED); + outb(0x60, status); +} + +static void ps2_handler(struct regs_t regs) +{ + uint8_t scancode = inb(0x60); + /* TODO: handle scancode */ +} + +static void ps2_set_scancode_set(uint8_t set) +{ + outb(0x60, 0xF0); + outb(0x60, set); +} + +void ps2_init(void) +{ + set_interrupt_handler(IRQ(1), ps2_handler); + ps2_set_scancode_set(1); +} diff --git a/drivers/tty.c b/drivers/tty.c index c2be189..6668be7 100644 --- a/drivers/tty.c +++ b/drivers/tty.c @@ -65,14 +65,20 @@ void tty_putchar(char ch) { term_x = 0; if(++term_y == VGA_HEIGHT) + { + tty_clear(); term_y = 0; + } } } else { term_x = 0; if(++term_y == VGA_HEIGHT) + { + tty_clear(); term_y = 0; + } } update_cursor(); } diff --git a/kernel/include/isr.h b/kernel/include/isr.h index 5d6d282..de81cd2 100644 --- a/kernel/include/isr.h +++ b/kernel/include/isr.h @@ -34,15 +34,18 @@ extern void _isr29(void); extern void _isr30(void); extern void _isr31(void); -/* installs all the ISR's */ +/* installs ISR's 0-31 */ void isr_init(void); /* This defines what the stack looks like after an ISR was running */ struct regs_t { - uint32_t gs, fs, es, ds; /* pushed the segs last */ + uint32_t gs, fs, es, ds; /* pushed the segs last */ uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */ - uint32_t int_no, err_code; /* our 'push byte #' and ecodes do this */ + uint32_t err_code; /* exceptions push this */ + uint32_t int_no; /* interrupt stubs do this */ uint32_t eip, cs, eflags, useresp, ss; /* pushed by the processor automatically */ -}; +} __attribute__((packed)); + +#define IRQ(x) (32+x) void set_interrupt_handler(uint8_t interrupt, void (*func)(struct regs_t)); diff --git a/kernel/include/panic.h b/kernel/include/panic.h new file mode 100644 index 0000000..db53e8e --- /dev/null +++ b/kernel/include/panic.h @@ -0,0 +1 @@ +void panic(const char*, ...); diff --git a/kernel/include/timer.h b/kernel/include/timer.h new file mode 100644 index 0000000..a7459a6 --- /dev/null +++ b/kernel/include/timer.h @@ -0,0 +1,7 @@ +#include <stdint.h> + +extern const uint64_t *current_tick; + +struct regs_t; + +void timer_init(void); diff --git a/kernel/irq.c b/kernel/irq.c index 5d48c46..d98ecda 100644 --- a/kernel/irq.c +++ b/kernel/irq.c @@ -55,6 +55,10 @@ void irq_handler(struct regs_t regs) { handler(regs); } + else + { + printf("WARNING: Unhandled IRQ: 0x%x!\n", regs.int_no); + } /* If the IDT entry that was invoked was greater than 40 * (meaning IRQ8 - 15), then we need to send an EOI to diff --git a/kernel/isr.c b/kernel/isr.c index a4627d0..cb59603 100644 --- a/kernel/isr.c +++ b/kernel/isr.c @@ -19,7 +19,7 @@ void isr_handler(struct regs_t regs) } else { - printf("WARNING: unhandled ISR"); + printf("WARNING: unhandled ISR!\n"); } } diff --git a/kernel/main.c b/kernel/main.c index 63ba635..119cf15 100644 --- a/kernel/main.c +++ b/kernel/main.c @@ -1,30 +1,40 @@ +#include <stdio.h> #include "gdt.h" #include "idt.h" #include "isr.h" #include "irq.h" +#include "ps2.h" +#include "timer.h" #include "tty.h" -#include <stdio.h> - -void interrupt(struct regs_t regs) -{ -} void main(struct multiboot_header *hdr, uint32_t magic) { + /* init the terminal first so we can get some output */ tty_init(); + /* then the descriptor tables so we can do more useful stuff */ gdt_init(); idt_init(); + /* install all the interrupt stubs */ isr_init(); irq_init(); - for(int i=0;i<256;++i) - set_interrupt_handler(i, interrupt); + /* initialize other drivers */ + timer_init(); + ps2_init(); asm("sti"); - printf("Boot finished.!\n"); + for(;;) + { + ps2_set_leds(0x01); + ps2_set_leds(0x02); + ps2_set_leds(0x04); + ps2_set_leds(0x02); + } + + printf("Boot finished.\n"); while(1) ; } diff --git a/kernel/timer.c b/kernel/timer.c new file mode 100644 index 0000000..4b700d7 --- /dev/null +++ b/kernel/timer.c @@ -0,0 +1,17 @@ +#include <stdint.h> +#include "isr.h" +#include "timer.h" + +uint64_t current_tick_data = 0; + +const uint64_t *current_tick = ¤t_tick_data; + +static void timer_callback(struct regs_t regs) +{ + ++current_tick_data; +} + +void timer_init(void) +{ + set_interrupt_handler(IRQ(0), timer_callback); +} diff --git a/libc/stdio.c b/libc/stdio.c index 4888338..17c5a2f 100644 --- a/libc/stdio.c +++ b/libc/stdio.c @@ -14,6 +14,21 @@ int puts(const char* str) return 0; } +static char hex_table[16] = { '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; + +static void print_hex(unsigned int n) +{ + unsigned mask = 0xF0000000; + unsigned shift = 28; + while(mask) + { + putchar(hex_table[(n & mask) >> shift]); + mask >>= 4; + shift -= 4; + } +} + int printf(const char *fmt, ...) { va_list ap; @@ -33,6 +48,9 @@ int printf(const char *fmt, ...) case 's': puts(va_arg(ap, const char*)); break; + case 'x': + print_hex(va_arg(ap, unsigned)); + break; default: puts("printf: unknown format\n"); break; |