diff options
Diffstat (limited to 'include/arch')
| -rw-r--r-- | include/arch/i686/drivers/gfx.h | 105 | ||||
| -rw-r--r-- | include/arch/i686/drivers/gfx_font.h | 4 | ||||
| -rw-r--r-- | include/arch/i686/drivers/pcspkr.h | 3 | ||||
| -rw-r--r-- | include/arch/i686/drivers/ps2_keymaps.h | 39 | ||||
| -rw-r--r-- | include/arch/i686/drivers/ps2kbd.h | 66 | ||||
| -rw-r--r-- | include/arch/i686/drivers/vgatext.h | 9 | ||||
| -rw-r--r-- | include/arch/i686/fpu.h | 2 | ||||
| -rw-r--r-- | include/arch/i686/gdt.h | 23 | ||||
| -rw-r--r-- | include/arch/i686/idt.h | 23 | ||||
| -rw-r--r-- | include/arch/i686/irq.h | 19 | ||||
| -rw-r--r-- | include/arch/i686/isr.h | 51 | ||||
| -rw-r--r-- | include/arch/i686/paging.h | 8 | ||||
| -rw-r--r-- | include/arch/i686/timer.h | 13 |
13 files changed, 365 insertions, 0 deletions
diff --git a/include/arch/i686/drivers/gfx.h b/include/arch/i686/drivers/gfx.h new file mode 100644 index 0000000..5e97100 --- /dev/null +++ b/include/arch/i686/drivers/gfx.h @@ -0,0 +1,105 @@ +#ifndef _GFX_H_ +#define _GFX_H_ + +#include <stdbool.h> +#include <stdint.h> + +enum vga_color_t { + VGA_BLACK = 0, + VGA_BLUE = 1, + VGA_GREEN = 2, + VGA_CYAN = 3, + VGA_RED = 4, + VGA_MAGENTA = 5, + VGA_BROWN = 6, + VGA_LIGHT_GRAY = 7, + VGA_DARK_GRAY = 8, + VGA_LIGHT_BLUE = 9, + VGA_LIGHT_GREEN = 10, + VGA_LIGHT_CYAN = 11, + VGA_LIGHT_RED = 12, + VGA_LIGHT_MAGENTA = 13, + VGA_LIGHT_BROWN = 14, + VGA_WHITE = 15 +}; + +#define VGA_WIDTH 80 +#define VGA_HEIGHT 25 + +#define VGA_MAKE_COLOR(fg, bg) (fg | bg << 4) +#define VGA_MAKE_ENTRY(ch, col) (((uint16_t)ch)|((uint16_t)col<<8)) +#define VGA_RGBPACK(r, g, b) ((r << 16)|(g << 8)|(b << 0)) + +#define GFX_WHITE 0xFFFFFF +#define GFX_BLACK 0x000000 + +struct vbe_info_t; + +bool gfx_init(struct vbe_info_t *vbe_mode_info); + +extern void (*gfx_drawpixel)(int x, int y); + +/* transparent background */ +void gfx_drawchar(int x, int y, int ch); + +/* fills the background with bgcolor */ +void gfx_drawchar_bg(int x, int y, int ch); + +void gfx_putchar(int ch); + +void gfx_puts(const char* str); + +/* this function can be different from resolution to resolution */ +extern void (*gfx_clear)(void); + +void gfx_reset(void); + +void gfx_set_foreground(uint32_t); + +uint32_t gfx_get_foreground(void); + +void gfx_set_background(uint32_t); + +uint32_t gfx_get_background(void); + +void (*gfx_hline)(int x1, int x2, int y); + +void (*gfx_vline)(int y1, int y2, int x); + +void gfx_fillrect(int x1, int y1, int w, int h); + +void gfx_drawline(int x1, int y1, int x2, int y2); + +/* these circle algorithms are very fast */ +void gfx_drawcircle(int cx, int cy, int rad); + +void gfx_fillcircle(int cx, int cy, int rad); + +void gfx_filltriangle(int x1, int y1, int x2, int y2, int x3, int y3); + +extern const uint16_t *gfx_width, *gfx_height; + +/* this is _BYTES_ per pixel, NOT BITS per pixel! */ +extern const uint8_t *gfx_bpp; + +struct bitmap_t { + unsigned int w, h; + unsigned int bpp; + uint8_t *data; +}; + +void gfx_bitmap(int x, int y, const struct bitmap_t*); + +void gfx_drawrect(int x, int y, int w, int h); + +void gfx_set_doublebuffer(bool); + +bool gfx_get_doublebuffer(void); + +/* don't call this wo/ double buffering! */ +void gfx_update(void); + +void gfx_putsxy(int, int, const char*); + +void gfx_putsxy_bg(int, int, const char*); +#endif diff --git a/include/arch/i686/drivers/gfx_font.h b/include/arch/i686/drivers/gfx_font.h new file mode 100644 index 0000000..f7db9d7 --- /dev/null +++ b/include/arch/i686/drivers/gfx_font.h @@ -0,0 +1,4 @@ +#include <stdint.h> +#define FONT_WIDTH 8 +#define FONT_HEIGHT 12 +extern const uint8_t gfx_font[][FONT_HEIGHT]; diff --git a/include/arch/i686/drivers/pcspkr.h b/include/arch/i686/drivers/pcspkr.h new file mode 100644 index 0000000..84e640f --- /dev/null +++ b/include/arch/i686/drivers/pcspkr.h @@ -0,0 +1,3 @@ +#include <stdint.h> + +void pcspkr_play(uint32_t freq); diff --git a/include/arch/i686/drivers/ps2_keymaps.h b/include/arch/i686/drivers/ps2_keymaps.h new file mode 100644 index 0000000..0e8ae26 --- /dev/null +++ b/include/arch/i686/drivers/ps2_keymaps.h @@ -0,0 +1,39 @@ +#include <stdint.h> + +#define EXTENDED_SCANCODE 0xE0 + +#define ERROR_KEY 0 +#define PRINTING_KEY 1 +#define SPECIAL_KEY 2 + +#define SPECIAL_NONE 0 +#define SPECIAL_SHIFT 1 +#define SPECIAL_CTRL 2 +#define SPECIAL_BKSP 3 +#define SPECIAL_ALT 4 +#define SPECIAL_GUI 5 +#define SPECIAL_NUMLOCK 6 +#define SPECIAL_CAPLOCK 7 +#define SPECIAL_SCRLLOCK 8 +#define SPECIAL_UPARROW 9 +#define SPECIAL_DNARROW 10 +#define SPECIAL_LFTARROW 11 +#define SPECIAL_RTARROW 12 +#define SPECIAL_ESC 13 +#define SPECIAL_F1 21 +#define SPECIAL_F2 22 +#define SPECIAL_F3 23 +#define SPECIAL_F4 24 +#define SPECIAL_F5 25 +#define SPECIAL_F6 26 +#define SPECIAL_F7 27 +#define SPECIAL_F8 28 +#define SPECIAL_F9 29 +#define SPECIAL_F10 30 +#define SPECIAL_F11 31 +#define SPECIAL_F12 32 + +extern uint8_t ps2_set1_scancodes[128]; +extern char ps2_set1_ascii[128]; +extern char ps2_set1_shift[128]; +extern uint8_t ps2_set1_special[128]; diff --git a/include/arch/i686/drivers/ps2kbd.h b/include/arch/i686/drivers/ps2kbd.h new file mode 100644 index 0000000..9e353ee --- /dev/null +++ b/include/arch/i686/drivers/ps2kbd.h @@ -0,0 +1,66 @@ +/* this is both a PS/2 keyboard AND a PS/2 MOUSE driver */ +#ifndef _PS2KBD_H_ +#define _PS2KBD_H_ + +#include <stdbool.h> +#include <stdint.h> + +#define PS2_SCROLL_LOCK (1 << 0) +#define PS2_NUM_LOCK (1 << 1) +#define PS2_CAPS_LOCK (1 << 2) + +#define BUTTON_UP (1 << 0) +#define BUTTON_LEFT (1 << 1) +#define BUTTON_DOWN (1 << 2) +#define BUTTON_RIGHT (1 << 3) + +#define MODIFIER_NONE 0 +#define MODIFIER_SHIFT (1 << 0) +#define MODIFIER_CTRL (1 << 1) +#define MODIFIER_ALT (1 << 2) + +struct ps2_specialkeys_t { + int shift :1; + int ctrl :1; + int bksp :1; + int alt :1; + int gui :1; + int numlock :1; + int capslock :1; + int scrllock :1; + int uparrow :1; + int downarrow :1; + int leftarrow :1; + int rightarrow :1; + int esc :1; + int f1 :1; + int f2 :1; + int f3 :1; + int f4 :1; + int f5 :1; + int f6 :1; + int f7 :1; + int f8 :1; + int f9 :1; + int f10 :1; + int f11 :1; + int f12 :1; +}; + +struct ps2_keyevent { + const struct ps2_specialkeys_t *special_keys; + char ascii; +}; + +/* returns which arrow keys are down */ +uint8_t ps2kbd_button_get(void); + +uint8_t ps2kbd_modifier_get(void); + +void ps2kbd_set_leds(uint8_t status); + +void ps2kbd_set_handler(void (*h)(const struct ps2_keyevent*)); + +void ps2kbd_init(void); + +#endif diff --git a/include/arch/i686/drivers/vgatext.h b/include/arch/i686/drivers/vgatext.h new file mode 100644 index 0000000..1cfe4c4 --- /dev/null +++ b/include/arch/i686/drivers/vgatext.h @@ -0,0 +1,9 @@ +#include <stdint.h> + +void vgatext_init(void); +void vgatext_clear(void); +void vgatext_set_color(uint8_t); +uint8_t vgatext_get_color(void); +void vgatext_putchar_at(int ch, uint8_t color, int x, int y); +void vgatext_putchar(int ch); +void vgatext_puts(const char*); diff --git a/include/arch/i686/fpu.h b/include/arch/i686/fpu.h new file mode 100644 index 0000000..0eb448a --- /dev/null +++ b/include/arch/i686/fpu.h @@ -0,0 +1,2 @@ +void fpu_enable(void); +void fpu_disable(void); diff --git a/include/arch/i686/gdt.h b/include/arch/i686/gdt.h new file mode 100644 index 0000000..4cf7c4f --- /dev/null +++ b/include/arch/i686/gdt.h @@ -0,0 +1,23 @@ +#include <stdint.h> + +struct gdt_entry { + uint16_t limit_low; + uint16_t base_low; + uint8_t base_middle; + uint8_t access; + uint8_t granularity; + uint8_t base_high; +} __attribute__((packed)); + +struct gdt_ptr { + uint16_t limit; + uint32_t base; +} __attribute__((packed)); + +struct gdt_entry gdt[3]; +struct gdt_ptr gp; + +/* assembly */ +extern void gdt_flush(uint32_t); + +void gdt_init(void); diff --git a/include/arch/i686/idt.h b/include/arch/i686/idt.h new file mode 100644 index 0000000..250ab82 --- /dev/null +++ b/include/arch/i686/idt.h @@ -0,0 +1,23 @@ +#include <stdint.h> + +struct idt_entry { + uint16_t base_lo; + uint16_t sel; + uint8_t zero; + uint8_t flags; + uint16_t base_hi; +} __attribute__((packed)); + +struct idt_ptr { + uint16_t limit; + uint32_t base; +} __attribute__((packed)); + +struct idt_entry idt[0x100]; +struct idt_ptr idt_pt; + +void idt_init(void); + +extern void idt_flush(uint32_t); + +void idt_set_gate(uint8_t idx, uint32_t base, uint16_t sel, uint8_t flags); diff --git a/include/arch/i686/irq.h b/include/arch/i686/irq.h new file mode 100644 index 0000000..13461e9 --- /dev/null +++ b/include/arch/i686/irq.h @@ -0,0 +1,19 @@ +extern void _irq0(void); +extern void _irq1(void); +extern void _irq2(void); +extern void _irq3(void); +extern void _irq4(void); +extern void _irq5(void); +extern void _irq6(void); +extern void _irq7(void); +extern void _irq8(void); +extern void _irq9(void); +extern void _irq10(void); +extern void _irq11(void); +extern void _irq12(void); +extern void _irq13(void); +extern void _irq14(void); +extern void _irq15(void); +extern void _int0x80(void); + +void irq_init(void); diff --git a/include/arch/i686/isr.h b/include/arch/i686/isr.h new file mode 100644 index 0000000..4cc7f1b --- /dev/null +++ b/include/arch/i686/isr.h @@ -0,0 +1,51 @@ +#include <stdint.h> + +/* these are all implemented in isr-as.S */ +extern void _isr0(void); +extern void _isr1(void); +extern void _isr2(void); +extern void _isr3(void); +extern void _isr4(void); +extern void _isr5(void); +extern void _isr6(void); +extern void _isr7(void); +extern void _isr8(void); +extern void _isr9(void); +extern void _isr10(void); +extern void _isr11(void); +extern void _isr12(void); +extern void _isr13(void); +extern void _isr14(void); +extern void _isr15(void); +extern void _isr16(void); +extern void _isr17(void); +extern void _isr18(void); +extern void _isr19(void); +extern void _isr20(void); +extern void _isr21(void); +extern void _isr22(void); +extern void _isr23(void); +extern void _isr24(void); +extern void _isr25(void); +extern void _isr26(void); +extern void _isr27(void); +extern void _isr28(void); +extern void _isr29(void); +extern void _isr30(void); +extern void _isr31(void); + +/* 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 edi, esi, ebp, esp, ebx, edx, ecx, eax; /* pushed by 'pusha' */ + uint32_t int_no; /* interrupt stubs do this */ + uint32_t err_code; /* exceptions push 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/include/arch/i686/paging.h b/include/arch/i686/paging.h new file mode 100644 index 0000000..0481069 --- /dev/null +++ b/include/arch/i686/paging.h @@ -0,0 +1,8 @@ +#define PAGE_PRESENT (1<<0) +#define PAGE_RW (1<<1) +#define PAGE_USER (1<<2) + +#define PAGE_MASK 0xFFFFF000 +#define PAGE_SIZE 0x1000 + +void paging_init(void); diff --git a/include/arch/i686/timer.h b/include/arch/i686/timer.h new file mode 100644 index 0000000..7a15949 --- /dev/null +++ b/include/arch/i686/timer.h @@ -0,0 +1,13 @@ +#include <stdint.h> + +#define HZ 100 +#define PIT_FREQ 1193182 + +extern volatile const uint64_t *current_tick; + +struct regs_t; + +void timer_init(uint32_t freq); + +/* NOTE: enables interrupts by default */ +void timer_delay(uint64_t ticks); |