aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/graphics
diff options
context:
space:
mode:
authorMarvin Borner2019-09-24 22:34:20 +0200
committerMarvin Borner2019-09-24 22:34:20 +0200
commit64ec44ba4575686849ba2597cf8bc9054af3d376 (patch)
tree059da7b1187ae31ff8979c1c936037dd990a0cd4 /src/kernel/graphics
parentd1d3820c6b306758cf90a269b0466febff6c808e (diff)
Added working VESA driver
Note to myself: Use Real/Protected mode correctly :)
Diffstat (limited to 'src/kernel/graphics')
-rw-r--r--src/kernel/graphics/graphics.h5
-rw-r--r--src/kernel/graphics/vesa.asm182
-rw-r--r--src/kernel/graphics/vesa.c43
-rw-r--r--src/kernel/graphics/vesa.h45
4 files changed, 54 insertions, 221 deletions
diff --git a/src/kernel/graphics/graphics.h b/src/kernel/graphics/graphics.h
index aa9440a..b28b550 100644
--- a/src/kernel/graphics/graphics.h
+++ b/src/kernel/graphics/graphics.h
@@ -20,9 +20,4 @@ void terminal_put_char(char c);
void terminal_write_line(const char *data);
-// VESA/VBE
-void init_graphics();
-
-struct vbe_best best;
-
#endif \ No newline at end of file
diff --git a/src/kernel/graphics/vesa.asm b/src/kernel/graphics/vesa.asm
deleted file mode 100644
index 820d592..0000000
--- a/src/kernel/graphics/vesa.asm
+++ /dev/null
@@ -1,182 +0,0 @@
-global vbe_set_mode
-global vbe_find_mode
-
-vbe_set_mode:
- mov [width], ax
- mov [height], bx
- mov [bpp], cl
-
- sti
-
- ; Get VBE BIOS info
- push es
- mov ax, 0x4F00
- mov di, [vbe_info]
- int 0x10
- pop es
-
- ; Check if BIOS has VBE support
- cmp ax, 0x4F
- jne error
-
- mov ax, word[vbe_info.video_modes]
- mov [offset], ax
- mov ax, word[vbe_info.video_modes+2]
- mov [mode_segment], ax
-
- mov ax, [mode_segment]
- mov fs, ax
- mov si, [offset]
-
-vbe_find_mode:
- mov dx, [fs:si]
- add si, 2
- mov [offset], si
- mov [mode], dx
- mov ax, 0
- mov fs, ax
-
- cmp [mode], word 0xFFFF
- je error
-
- ; Get VBE mode info
- push es
- mov ax, 0x4F01
- mov cx, [mode]
- mov di, [vbe_mode_info]
- int 0x10
- pop es
-
- cmp ax, 0x4F
- jne error
-
- mov ax, [width]
- cmp ax, [vbe_mode_info.width]
- jne next_mode
-
- mov ax, [height]
- cmp ax, [vbe_mode_info.height]
- jne next_mode
-
- mov al, [bpp]
- cmp al, [vbe_mode_info.bpp]
- jne next_mode
-
- ; Found best mode!
- mov ax, [width]
- mov word[vbe_best.width], ax
- mov ax, [height]
- mov word[vbe_best.height], ax
- mov eax, [vbe_mode_info.framebuffer]
- mov dword[vbe_best.framebuffer], eax
- mov ax, [vbe_mode_info.pitch]
- mov word[vbe_best.bytes_per_line], ax
- mov eax, 0
- mov al, [bpp]
- mov byte[vbe_best.bpp], al
- shr eax, 3
- mov dword[vbe_best.bytes_per_pixel], eax
-
- mov ax, [width]
- shr ax, 3
- dec ax
- mov word[vbe_best.x_cur_max], ax
-
- mov ax, [height]
- shr ax, 4
- dec ax
- mov word[vbe_best.y_cur_max], ax
-
- ; Set the mode
- push es
- mov ax, 0x4F02
- mov bx, [mode]
- or bx, 0x4000
- mov di, 0
- int 0x10
- pop es
-
- cmp ax, 0x4F
- jne error
-
- clc
- ret
-
-next_mode:
- mov ax, [mode_segment]
- mov fs, ax
- mov si, [offset]
- jmp vbe_find_mode
-
-error:
- stc
- ret
-
-width dw 0
-height dw 0
-bpp db 0
-mode_segment dw 0
-offset dw 0
-mode dw 0
-
-vbe_info:
- .signature db "VESA"
- .version dw 0
- .oem dd 0
- .capabilities dd 0
- .video_modes dd 0
- .video_memory dw 0
- .software_rev dw 0
- .vendor dd 0
- .product_name dd 0
- .product_rev dd 0
- .reserved times 222 db 0
- .oem_data times 256 db 0
-
-vbe_mode_info:
- .attributes dw 0
- .window_a db 0
- .window_b db 0
- .granularity dw 0
- .window_size dw 0
- .segment_a dw 0
- .segment_b dw 0
- .win_func_ptr dd 0
- .pitch dw 0
- .width dw 0
- .height dw 0
- .w_char db 0
- .y_char db 0
- .planes db 0
- .bpp db 0
- .banks db 0
- .memory_model db 0
- .bank_size db 0
- .image_pages db 0
- .reserved0 db 0
-
- .red_mask db 0
- .red_position db 0
- .green_mask db 0
- .green_position db 0
- .blue_mask db 0
- .blue_position db 0
- .reserved_mask db 0
- .reserved_position db 0
- .direct_color_attributes db 0
-
- .framebuffer dd 0
- .off_screen_mem_off dd 0
- .off_screen_mem_size dw 0
- .reserved1 times 206 db 0
-
-vbe_best:
- .bpp db 0
- .height dw 0
- .width dw 0
- .mode dw 0
- .framebuffer dd 0
- .bytes_per_line dw 0
- .bytes_per_pixel dd 0
- .x_cur_max dw 0
- .y_cur_max dw 0 \ No newline at end of file
diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c
index 3549d66..af2502b 100644
--- a/src/kernel/graphics/vesa.c
+++ b/src/kernel/graphics/vesa.c
@@ -1,11 +1,42 @@
#include "vesa.h"
-extern struct vbe_best vbe_find_mode();
+vbe_mode_info *vbe_set_mode(unsigned short mode) {
+ regs16_t regs;
+ regs.ax = 0x4F02;
+ regs.bx = mode | (1 << 14);
+ int32(0x10, &regs);
-extern void vbe_set_mode(struct vbe_best);
+ if (regs.ax == 0x004F) {
+ regs.ax = 0x4F01;
+ regs.cx = mode;
+ regs.di = 0x0000;
+ regs.es = 0xA000;
+ int32(0x10, &regs);
+ if (regs.ax != 0x004F) {
+ // Add VGA redirect
+ }
-struct vbe_best best;
+ vbe_mode_info *vbe_info = (vbe_mode_info *) 0xA0000;
-void init_graphics() {
- best = vbe_find_mode();
-} \ No newline at end of file
+ vbe_width = vbe_info->width;
+ vbe_height = vbe_info->height;
+ vbe_bpp = vbe_info->bpp / 8;
+ vbe_pitch = vbe_info->pitch;
+
+ char *fb = (char *) vbe_info->framebuffer;
+ for (int i = 0; i < 640 * 480 * 3; i++) {
+ fb[i] = 100;
+ }
+ regs.ax = 0x0000;
+ int32(0x16, &regs);
+ regs.ax = 0x0003;
+ int32(0x10, &regs);
+
+ return vbe_info;
+ } else {
+ // Add VGA redirect
+ }
+
+ vbe_mode_info vbe_info;
+ return &vbe_info;
+}
diff --git a/src/kernel/graphics/vesa.h b/src/kernel/graphics/vesa.h
index 9023029..fb9ff54 100644
--- a/src/kernel/graphics/vesa.h
+++ b/src/kernel/graphics/vesa.h
@@ -3,33 +3,7 @@
#include <stdint.h>
-struct vbe_best {
- uint8_t bpp;
- uint16_t height;
- uint16_t width;
- uint32_t framebuffer;
- uint32_t bytes_per_line;
- uint32_t bytes_per_pixel;
- uint32_t x_cur_max;
- uint32_t y_cur_max;
-} __attribute__ ((packed));
-
-struct vbe_info {
- char signature[4]; // must be "VESA" to indicate valid VBE support
- uint16_t version; // VBE version; high byte is major version, low byte is minor version
- uint32_t oem; // segment:offset pointer to OEM
- uint32_t capabilities; // bitfield that describes card capabilities
- uint32_t video_modes; // segment:offset pointer to list of supported video modes
- uint16_t video_memory; // amount of video memory in 64KB blocks
- uint16_t software_rev; // software revision
- uint32_t vendor; // segment:offset to card vendor string
- uint32_t product_name; // segment:offset to card model name
- uint32_t product_rev; // segment:offset pointer to product revision
- char reserved[222]; // reserved for future expansion
- char oem_data[256]; // OEM BIOSes store their strings in this area
-} __attribute__ ((packed));
-
-struct vbe_mode_info {
+typedef struct __attribute__ ((packed)) {
uint16_t attributes; // deprecated, only bit 7 should be of interest to you, and it indicates the mode supports a linear frame buffer.
uint8_t window_a; // deprecated
uint8_t window_b; // deprecated
@@ -65,6 +39,21 @@ struct vbe_mode_info {
uint32_t off_screen_mem_off;
uint16_t off_screen_mem_size; // size of memory in the framebuffer but not being displayed on the screen
uint8_t reserved1[206];
-} __attribute__ ((packed));
+} vbe_mode_info;
+
+vbe_mode_info *vbe_set_mode(unsigned short mode);
+
+typedef struct __attribute__ ((packed)) {
+ unsigned short di, si, bp, sp, bx, dx, cx, ax;
+ unsigned short gs, fs, es, ds, eflags;
+} regs16_t;
+
+extern void int32(unsigned char intnum, regs16_t *regs);
+
+int vbe_current_mode;
+int vbe_width;
+int vbe_height;
+int vbe_bpp;
+int vbe_pitch;
#endif