mirror of
https://github.com/cowmonk/cowos.git
synced 2025-10-27 22:43:26 +00:00
cowos attempted gdt, but at least we have vga drivers now
This commit is contained in:
parent
b08b0728ae
commit
41b34d2a9d
14 changed files with 253 additions and 140 deletions
|
|
@ -2,49 +2,30 @@
|
|||
#define VGA_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
/* hardware text mode const */
|
||||
enum vga_color {
|
||||
VGA_COLOR_BLACK = 0,
|
||||
VGA_COLOR_BLUE = 1,
|
||||
VGA_COLOR_GREEN = 2,
|
||||
VGA_COLOR_CYAN = 3,
|
||||
VGA_COLOR_RED = 4,
|
||||
VGA_COLOR_MAGENTA = 5,
|
||||
VGA_COLOR_BROWN = 6,
|
||||
VGA_COLOR_LIGHT_GREY = 7,
|
||||
VGA_COLOR_DARK_GREY = 8,
|
||||
VGA_COLOR_LIGHT_BLUE = 9,
|
||||
VGA_COLOR_LIGHT_GREEN = 10,
|
||||
VGA_COLOR_LIGHT_CYAN = 11,
|
||||
VGA_COLOR_LIGHT_RED = 12,
|
||||
VGA_COLOR_LIGHT_MAGENTA = 13,
|
||||
VGA_COLOR_LIGHT_BROWN = 14,
|
||||
VGA_COLOR_WHITE = 15,
|
||||
};
|
||||
// VGA mem addr
|
||||
#define VGA_TEXT_BUFFER 0xB8000 // Text mode video memory
|
||||
#define VGA_GRAPHICS_BUFFER 0xA0000 // Graphics mode video memory
|
||||
|
||||
static inline uint8_t
|
||||
vga_entry_color(enum vga_color fg, enum vga_color bg)
|
||||
{
|
||||
return fg | bg << 4;
|
||||
}
|
||||
// VGA mode 13h dimensions
|
||||
#define VGA_WIDTH 320
|
||||
#define VGA_HEIGHT 200
|
||||
|
||||
static inline uint16_t
|
||||
vga_entry(unsigned char uc, uint8_t color)
|
||||
{
|
||||
return (uint16_t) uc | (uint16_t) color << 8;
|
||||
}
|
||||
// VGA register IO ports
|
||||
#define VGA_AC_INDEX 0x3C0 // attribute controller index
|
||||
#define VGA_AC_WRITE 0x3C0 // attribute controller write
|
||||
#define VGA_AC_READ 0x3C1 // attribute controller read
|
||||
#define VGA_MISC_WRITE 0x3C2 // miscellaneous output register
|
||||
#define VGA_SEQ_INDEX 0x3C4 // sequencer index
|
||||
#define VGA_SEQ_DATA 0x3C5 // sequencer data
|
||||
#define VGA_GC_INDEX 0x3CE // graphics controller index
|
||||
#define VGA_GC_DATA 0x3CF // graphics controller data
|
||||
#define VGA_CRTC_INDEX 0x3D4 // CRT controller index
|
||||
#define VGA_CRTC_DATA 0x3D5 // CRT controller data
|
||||
#define VGA_INSTAT_READ 0x3DA // input status read
|
||||
|
||||
/* using mode 3 of VGA 80x25 */
|
||||
#define VGA_WIDTH 80
|
||||
#define VGA_HEIGHT 25
|
||||
#define VGA_MEMORY 0xA0000 /* VGA memory location */
|
||||
void vga_set_mode_13h(void);
|
||||
void vga_put_pixel(uint16_t x, uint16_t y, uint8_t color);
|
||||
void vga_clear_screen(uint8_t color);
|
||||
|
||||
void term_init(void);
|
||||
void term_setcolor(uint8_t color);
|
||||
void term_putentryat(char c, uint8_t color, size_t x, size_t y);
|
||||
void term_putchar(char c);
|
||||
void term_writestr(const char* data);
|
||||
|
||||
#endif // VGA_H
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,22 +0,0 @@
|
|||
#ifndef FB_H
|
||||
#define FB_H
|
||||
|
||||
/* *pixel = vram + y*pitch + x*pixelwidth */
|
||||
|
||||
/*
|
||||
| width | how many pixels you have on a horizontal line |
|
||||
|===========================================================================|
|
||||
| height | how many horizontal lines of pixels are present |
|
||||
|===========================================================================|
|
||||
| pitch | how many bytes of VRAM you should skip to go one pixel down |
|
||||
|===========================================================================|
|
||||
| depth | how many bits of color you have |
|
||||
|===========================================================================|
|
||||
| pixelwidth | how many bytes of VRAM you should skip to go one pixel right |
|
||||
*/
|
||||
|
||||
#include <klibc/types.h>
|
||||
|
||||
void putpixel(int pos_x, int pos_y, unsigned char VGA_COLOR);
|
||||
|
||||
#endif /* FB_H */
|
||||
28
kernel/include/gdt.h
Normal file
28
kernel/include/gdt.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include <stdint.h>
|
||||
|
||||
#ifndef GDT_H
|
||||
#define GDT_H
|
||||
|
||||
typedef struct GDTEntry {
|
||||
uint16_t limit;
|
||||
uint16_t base_low;
|
||||
uint16_t base_mid;
|
||||
uint8_t base_high;
|
||||
uint8_t access;
|
||||
uint8_t granularity;
|
||||
} __attribute__((packed)) GDTEntry;
|
||||
|
||||
typedef struct GDTPtr {
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} __attribute__((packed)) GDTPtr;
|
||||
|
||||
#define GDT_NUM_ENTRIES 5 /* including null descriptor */
|
||||
#define GDT_KERNEL_CODE 0x08
|
||||
#define GDT_KERNEL_DATA 0x10
|
||||
#define GDT_USER_CODE 0x18
|
||||
#define GDT_USER_DATA 0x20
|
||||
|
||||
void initGDT();
|
||||
|
||||
#endif /* GDT_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue