[vid] Working on VBE graphics support for Bochs/Qemu
This commit is contained in:
parent
4c475a2d29
commit
4d3118bad7
8
Makefile
8
Makefile
@ -13,6 +13,7 @@ ECHO = `which echo` -e
|
||||
# Feel free to be specific, but I'd rather you not be.
|
||||
MODULES = $(patsubst %.c,%.o,$(wildcard kernel/core/*.c))
|
||||
FILESYSTEMS = $(patsubst %.c,%.o,$(wildcard kernel/core/fs/*.c))
|
||||
VIDEODRIVERS = $(patsubst %.c,%.o,$(wildcard kernel/core/video/*.c))
|
||||
EMU = qemu
|
||||
GENEXT = genext2fs
|
||||
DD = dd conv=notrunc
|
||||
@ -29,7 +30,7 @@ install: toaruos-initrd toaruos-kernel
|
||||
@${ECHO} "\r\033[34;1m -- Kernel and ramdisk installed.\033[0m"
|
||||
|
||||
run: toaruos-kernel toaruos-initrd
|
||||
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -serial stdio
|
||||
${EMU} -kernel toaruos-kernel -initrd toaruos-initrd -serial stdio -vga std
|
||||
|
||||
#################
|
||||
# Documentation #
|
||||
@ -46,9 +47,9 @@ docs/core.pdf: docs/*.tex
|
||||
################
|
||||
# Kernel #
|
||||
################
|
||||
toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o ${MODULES} ${FILESYSTEMS}
|
||||
toaruos-kernel: kernel/start.o kernel/link.ld kernel/main.o ${MODULES} ${FILESYSTEMS} ${VIDEODRIVERS}
|
||||
@${ECHO} -n "\033[32m LD $<\033[0m"
|
||||
@${LD} -T kernel/link.ld -o toaruos-kernel kernel/*.o kernel/core/*.o kernel/core/fs/*.o
|
||||
@${LD} -T kernel/link.ld -o toaruos-kernel kernel/*.o kernel/core/*.o kernel/core/fs/*.o kernel/core/video/*.o
|
||||
@${ECHO} "\r\033[32;1m LD $<\033[0m"
|
||||
@${ECHO} "\033[34;1m -- Kernel is ready!\033[0m"
|
||||
|
||||
@ -148,6 +149,7 @@ clean:
|
||||
@-rm -f kernel/*.o
|
||||
@-rm -f kernel/core/*.o
|
||||
@-rm -f kernel/core/fs/*.o
|
||||
@-rm -f kernel/core/video/*.o
|
||||
@-rm -f bootloader/stage1.bin
|
||||
@-rm -f bootloader/stage1/*.o
|
||||
@-rm -f bootloader/stage2.bin
|
||||
|
@ -198,7 +198,21 @@ start_shell() {
|
||||
} else if (!strcmp(cmd, "exit")) {
|
||||
kprintf("Good byte.\n");
|
||||
break;
|
||||
}else {
|
||||
} else if (!strcmp(cmd, "short-text")) {
|
||||
kprintf("I'm going to make text shorter. This is a silly demo.\n");
|
||||
outportb(0x3D4, 0x9);
|
||||
outportb(0x3D5, 0x0E);
|
||||
} else if (!strcmp(cmd, "vid-mode")) {
|
||||
if (tokenid < 2) {
|
||||
kprintf("Please select a graphics driver: bochs\n");
|
||||
} else {
|
||||
if (!strcmp(argv[1], "bochs")) {
|
||||
graphics_install_bochs();
|
||||
} else {
|
||||
kprintf("Unknown graphics driver: %s\n", argv[1]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
kprintf("Unrecognized command: %s\n", cmd);
|
||||
}
|
||||
}
|
||||
|
@ -91,6 +91,19 @@ strlen(
|
||||
return i;
|
||||
}
|
||||
|
||||
uint32_t __attribute__ ((pure)) krand() {
|
||||
static uint32_t x = 123456789;
|
||||
static uint32_t y = 362436069;
|
||||
static uint32_t z = 521288629;
|
||||
static uint32_t w = 88675123;
|
||||
|
||||
uint32_t t;
|
||||
|
||||
t = x ^ (x << 11);
|
||||
x = y; y = z; z = w;
|
||||
return w = w ^ (w >> 19) ^ t ^ (t >> 8);
|
||||
}
|
||||
|
||||
/*
|
||||
* atoi
|
||||
* Naïve implementation thereof.
|
||||
@ -110,6 +123,24 @@ atoi(
|
||||
return out;
|
||||
}
|
||||
|
||||
unsigned short
|
||||
inports(
|
||||
unsigned short _port
|
||||
) {
|
||||
unsigned short rv;
|
||||
__asm__ __volatile__ ("inw %1, %0" : "=a" (rv) : "dN" (_port));
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
outports(
|
||||
unsigned short _port,
|
||||
unsigned short _data
|
||||
) {
|
||||
__asm__ __volatile__ ("outw %1, %0" : : "dN" (_port), "a" (_data));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* inportb
|
||||
* Read from an I/O port.
|
||||
|
45
kernel/core/video/bochs.c
Normal file
45
kernel/core/video/bochs.c
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* vim:tabstop=4
|
||||
* vim:noexpandtab
|
||||
*
|
||||
* Bochs VBE / QEMU vga=std Graphics Driver
|
||||
*/
|
||||
|
||||
#include <system.h>
|
||||
|
||||
void
|
||||
graphics_install_bochs() {
|
||||
outports(0x1CE, 0x00);
|
||||
outports(0x1CF, 0xB0C4);
|
||||
short i = inports(0x1CF);
|
||||
kprintf("Bochs VBE Mode [%x]\n", (unsigned int)i);
|
||||
kprintf("Switching to GRAPHICS MODE!\n");
|
||||
timer_wait(90);
|
||||
/* Disable VBE */
|
||||
outports(0x1CE, 0x04);
|
||||
outports(0x1CF, 0x00);
|
||||
/* Set X resolution to 1024 */
|
||||
outports(0x1CE, 0x01);
|
||||
outports(0x1CF, 1024);
|
||||
/* Set Y resolution to 768 */
|
||||
outports(0x1CE, 0x02);
|
||||
outports(0x1CF, 768);
|
||||
/* Set bpp to 8 */
|
||||
outports(0x1CE, 0x03);
|
||||
outports(0x1CF, 0x20);
|
||||
/* Re-enable VBE */
|
||||
outports(0x1CE, 0x04);
|
||||
outports(0x1CF, 0x41);
|
||||
/* Let's draw some stuff */
|
||||
uint32_t * vid_mem = (uint32_t *)0xA0000;
|
||||
uint32_t x = 0;
|
||||
while (x < 1024 * 768) {
|
||||
if ((x / 1024) % 2) {
|
||||
*vid_mem = 0x00FF0000;
|
||||
} else {
|
||||
*vid_mem = krand();
|
||||
}
|
||||
++vid_mem;
|
||||
++x;
|
||||
}
|
||||
}
|
@ -18,11 +18,14 @@ extern int strlen(const char *str);
|
||||
extern int atoi(const char *str);
|
||||
extern unsigned char inportb(unsigned short _port);
|
||||
extern void outportb(unsigned short _port, unsigned char _data);
|
||||
extern unsigned short inports(unsigned short _port);
|
||||
extern void outports(unsigned short _port, unsigned short _data);
|
||||
extern int strcmp(const char *a, const char *b);
|
||||
extern char * strtok_r(char * str, const char * delim, char ** saveptr);
|
||||
extern size_t lfind(const char * str, const char accept);
|
||||
extern size_t strspn(const char * str, const char * accept);
|
||||
extern char * strpbrk(const char * str, const char * accept);
|
||||
extern uint32_t krand();
|
||||
|
||||
/* Panic */
|
||||
#define HALT_AND_CATCH_FIRE(mesg) halt_and_catch_fire(mesg, __FILE__, __LINE__)
|
||||
@ -177,4 +180,8 @@ uintptr_t initial_esp;
|
||||
/* CMOS */
|
||||
extern void get_time(uint16_t * hours, uint16_t * minutes, uint16_t * seconds);
|
||||
|
||||
/* Video Drivers */
|
||||
/* BOCHS / QEMU VBE Driver */
|
||||
extern void graphics_install_bochs();
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user