Video as a module, kill device_init
This commit is contained in:
parent
0122c943aa
commit
9b5cf9cec5
11
Makefile
11
Makefile
@ -58,6 +58,7 @@ BOOT_MODULES += procfs tmpfs ata
|
||||
BOOT_MODULES += ext2
|
||||
BOOT_MODULES += debug_shell
|
||||
BOOT_MODULES += ps2mouse ps2kbd
|
||||
BOOT_MODULES += lfbvideo
|
||||
|
||||
# This is kinda silly. We're going to form an -initrd argument..
|
||||
# which is basically -initrd "hdd/mod/%.ko,hdd/mod/%.ko..."
|
||||
@ -103,15 +104,15 @@ run: system
|
||||
kvm: system
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu $(DISK_ROOT)"
|
||||
vga: system
|
||||
${EMU} ${EMUARGS} -append "vgaterm $(DISK_ROOT)"
|
||||
${EMU} ${EMUARGS} -append "start=--vga $(DISK_ROOT)"
|
||||
vga-kvm: system
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "vgaterm $(DISK_ROOT)"
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "start=--vga $(DISK_ROOT)"
|
||||
term: system
|
||||
${EMU} ${EMUARGS} -append "vid=qemu single $(DISK_ROOT)"
|
||||
${EMU} ${EMUARGS} -append "vid=qemu start=--single $(DISK_ROOT)"
|
||||
term-kvm: system
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu single $(DISK_ROOT)"
|
||||
${EMU} ${EMUARGS} ${EMUKVM} -append "vid=qemu start=--single $(DISK_ROOT)"
|
||||
headless: system
|
||||
${EMU} ${EMUARGS} -display none -append "vgaterm $(DISK_ROOT)"
|
||||
${EMU} ${EMUARGS} -display none -append "start=--vga $(DISK_ROOT)"
|
||||
run-config: system
|
||||
util/config-parser ${EMU}
|
||||
|
||||
|
@ -201,18 +201,6 @@ extern uint32_t now(void);
|
||||
extern int detect_cpu(void);
|
||||
|
||||
/* Video Drivers */
|
||||
/* Generic (pre-set, 32-bit, linear frame buffer) */
|
||||
extern void graphics_install_preset(uint16_t, uint16_t);
|
||||
extern uint16_t lfb_resolution_x;
|
||||
extern uint16_t lfb_resolution_y;
|
||||
extern uint16_t lfb_resolution_b;
|
||||
extern uintptr_t lfb_get_address(void);
|
||||
extern uint8_t * lfb_vid_memory;
|
||||
|
||||
/* BOCHS / QEMU VBE Driver */
|
||||
extern void graphics_install_bochs(uint16_t, uint16_t);
|
||||
extern void bochs_set_y_offset(uint16_t y);
|
||||
extern uint16_t bochs_current_scroll(void);
|
||||
|
||||
/* Floating Point Unit */
|
||||
void switch_fpu(void);
|
||||
|
9
kernel/include/video.h
Normal file
9
kernel/include/video.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _LFB_VIDEO_H
|
||||
#define _LFB_VIDEO_H
|
||||
|
||||
#define IO_VID_WIDTH 0x5001
|
||||
#define IO_VID_HEIGHT 0x5002
|
||||
#define IO_VID_DEPTH 0x5003
|
||||
#define IO_VID_ADDR 0x5004
|
||||
|
||||
#endif
|
@ -69,10 +69,6 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
|
||||
char cmdline_[1024];
|
||||
|
||||
if (mboot_ptr->vbe_mode_info) {
|
||||
lfb_vid_memory = (uint8_t *)((vbe_info_t *)(mboot_ptr->vbe_mode_info))->physbase;
|
||||
}
|
||||
|
||||
if (mboot_ptr->flags & (1 << 3)) {
|
||||
debug_print(NOTICE, "There %s %d module%s starting at 0x%x.", mboot_ptr->mods_count == 1 ? "is" : "are", mboot_ptr->mods_count, mboot_ptr->mods_count == 1 ? "" : "s", mboot_ptr->mods_addr);
|
||||
debug_print(NOTICE, "Current kernel heap start point would be 0x%x.", &end);
|
||||
@ -131,10 +127,6 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
shm_install(); /* Install shared memory */
|
||||
modules_install(); /* Modules! */
|
||||
|
||||
debug_print_vfs_tree();
|
||||
|
||||
early_stage_args();
|
||||
|
||||
/* Load modules from bootloader */
|
||||
debug_print(NOTICE, "%d modules to load", mboot_mods_count);
|
||||
for (unsigned int i = 0; i < mboot_ptr->mods_count; ++i ) {
|
||||
@ -157,13 +149,20 @@ int kmain(struct multiboot *mboot, uint32_t mboot_mag, uintptr_t esp) {
|
||||
/* Map /dev to a device mapper */
|
||||
map_vfs_directory("/dev");
|
||||
|
||||
late_stage_args();
|
||||
if (args_present("start")) {
|
||||
char * c = args_value("start");
|
||||
if (!c) {
|
||||
debug_print(WARNING, "Expected an argument to kernel option `start`. Ignoring.");
|
||||
} else {
|
||||
debug_print(NOTICE, "Got start argument: %s", c);
|
||||
boot_arg = strdup(c);
|
||||
}
|
||||
}
|
||||
|
||||
/* Prepare to run /bin/init */
|
||||
char * argv[] = {
|
||||
"/bin/init",
|
||||
boot_arg,
|
||||
boot_arg_extra,
|
||||
NULL
|
||||
};
|
||||
int argc = 0;
|
||||
|
@ -1,57 +0,0 @@
|
||||
#include <system.h>
|
||||
#include <logging.h>
|
||||
#include <args.h>
|
||||
#include <tokenize.h>
|
||||
#include <fs.h>
|
||||
|
||||
void early_stage_args(void) {
|
||||
char * c;
|
||||
|
||||
if ((c = args_value("vid"))) {
|
||||
debug_print(NOTICE, "Video mode requested: %s", c);
|
||||
|
||||
char * arg = strdup(c);
|
||||
char * argv[10];
|
||||
int argc = tokenize(arg, ",", argv);
|
||||
|
||||
uint16_t x, y;
|
||||
if (argc < 3) {
|
||||
x = 1024;
|
||||
y = 768;
|
||||
} else {
|
||||
x = atoi(argv[1]);
|
||||
y = atoi(argv[2]);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[0], "qemu")) {
|
||||
/* Bochs / Qemu Video Device */
|
||||
graphics_install_bochs(x,y);
|
||||
} else if (!strcmp(argv[0],"preset")) {
|
||||
graphics_install_preset(x,y);
|
||||
} else {
|
||||
debug_print(WARNING, "Unrecognized video adapter: %s", argv[0]);
|
||||
}
|
||||
|
||||
free(arg);
|
||||
}
|
||||
|
||||
if (args_present("single")) {
|
||||
boot_arg = "--single";
|
||||
} else if (args_present("lite")) {
|
||||
boot_arg = "--special";
|
||||
} else if (args_present("vgaterm")) {
|
||||
boot_arg = "--vga";
|
||||
} else if (args_present("start")) {
|
||||
char * c = args_value("start");
|
||||
if (!c) {
|
||||
debug_print(WARNING, "Expected an argument to kernel option `start`. Ignoring.");
|
||||
} else {
|
||||
boot_arg_extra = c;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void late_stage_args(void) {
|
||||
/* Nothing to do here */
|
||||
}
|
@ -300,10 +300,6 @@ static int execve(const char * filename, char *const argv[], char *const envp[])
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int getgraphicsaddress(void) {
|
||||
return (int)lfb_get_address();
|
||||
}
|
||||
|
||||
static int seek(int fd, int offset, int whence) {
|
||||
if (fd >= (int)current_process->fds->length || fd < 0) {
|
||||
return -1;
|
||||
@ -392,23 +388,6 @@ static int stat(int fd, uintptr_t st) {
|
||||
return stat_node(fn, st);
|
||||
}
|
||||
|
||||
static int setgraphicsoffset(int rows) {
|
||||
bochs_set_y_offset(rows);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int getgraphicswidth(void) {
|
||||
return lfb_resolution_x;
|
||||
}
|
||||
|
||||
static int getgraphicsheight(void) {
|
||||
return lfb_resolution_y;
|
||||
}
|
||||
|
||||
static int getgraphicsdepth(void) {
|
||||
return lfb_resolution_b;
|
||||
}
|
||||
|
||||
static int mkpipe(void) {
|
||||
fs_node_t * node = make_pipe(4096 * 2);
|
||||
return process_append_fd((process_t *)current_process, node);
|
||||
@ -740,16 +719,16 @@ static uintptr_t syscalls[] = {
|
||||
(uintptr_t)&fork, /* 8 */
|
||||
(uintptr_t)&sys_getpid,
|
||||
(uintptr_t)&sys_sbrk,
|
||||
(uintptr_t)&getgraphicsaddress,
|
||||
(uintptr_t)&RESERVED,
|
||||
(uintptr_t)&uname, /* 12 */
|
||||
(uintptr_t)&openpty,
|
||||
(uintptr_t)&seek,
|
||||
(uintptr_t)&stat,
|
||||
(uintptr_t)&setgraphicsoffset, /* 16 */
|
||||
(uintptr_t)&RESERVED, /* 16 */
|
||||
(uintptr_t)&wait,
|
||||
(uintptr_t)&getgraphicswidth,
|
||||
(uintptr_t)&getgraphicsheight,
|
||||
(uintptr_t)&getgraphicsdepth, /* 20 */
|
||||
(uintptr_t)&RESERVED,
|
||||
(uintptr_t)&RESERVED,
|
||||
(uintptr_t)&RESERVED, /* 20 */
|
||||
(uintptr_t)&mkpipe,
|
||||
(uintptr_t)&dup2,
|
||||
(uintptr_t)&getuid,
|
||||
|
@ -8,45 +8,90 @@
|
||||
#include <types.h>
|
||||
#include <logging.h>
|
||||
#include <pci.h>
|
||||
#include <boot.h>
|
||||
#include <args.h>
|
||||
#include <tokenize.h>
|
||||
#include <module.h>
|
||||
#include <video.h>
|
||||
|
||||
#define PREFERRED_VY 4096
|
||||
#define PREFERRED_B 32
|
||||
/* Generic (pre-set, 32-bit, linear frame buffer) */
|
||||
static void graphics_install_preset(uint16_t, uint16_t);
|
||||
|
||||
uint16_t lfb_resolution_x = 0;
|
||||
uint16_t lfb_resolution_y = 0;
|
||||
uint16_t lfb_resolution_b = 0;
|
||||
static uint16_t lfb_resolution_x = 0;
|
||||
static uint16_t lfb_resolution_y = 0;
|
||||
static uint16_t lfb_resolution_b = 0;
|
||||
|
||||
/* BOCHS / QEMU VBE Driver */
|
||||
static void graphics_install_bochs(uint16_t, uint16_t);
|
||||
static void bochs_set_y_offset(uint16_t y);
|
||||
static uint16_t bochs_current_scroll(void);
|
||||
|
||||
/*
|
||||
* Address of the linear frame buffer.
|
||||
* This can move, so it's a pointer instead of
|
||||
* #define.
|
||||
*/
|
||||
uint8_t * lfb_vid_memory = (uint8_t *)0xE0000000;
|
||||
static uint8_t * lfb_vid_memory = (uint8_t *)0xE0000000;
|
||||
|
||||
static int ioctl_vid(fs_node_t * node, int request, void * argp) {
|
||||
/* TODO: Make this actually support multiple video devices */
|
||||
|
||||
switch (request) {
|
||||
case IO_VID_WIDTH:
|
||||
validate(argp);
|
||||
*((size_t *)argp) = lfb_resolution_x;
|
||||
return 0;
|
||||
case IO_VID_HEIGHT:
|
||||
validate(argp);
|
||||
*((size_t *)argp) = lfb_resolution_y;
|
||||
return 0;
|
||||
case IO_VID_DEPTH:
|
||||
validate(argp);
|
||||
*((size_t *)argp) = lfb_resolution_b;
|
||||
return 0;
|
||||
case IO_VID_ADDR:
|
||||
validate(argp);
|
||||
*((uintptr_t *)argp) = (uintptr_t)lfb_vid_memory;
|
||||
return 0;
|
||||
default:
|
||||
return -1; /* TODO EINV... something or other */
|
||||
}
|
||||
}
|
||||
|
||||
static fs_node_t * lfb_video_device_create(void /* TODO */) {
|
||||
fs_node_t * fnode = malloc(sizeof(fs_node_t));
|
||||
memset(fnode, 0x00, sizeof(fs_node_t));
|
||||
sprintf(fnode->name, "fb0"); /* TODO */
|
||||
fnode->length = lfb_resolution_x * lfb_resolution_y * (lfb_resolution_b / 8);
|
||||
fnode->flags = FS_BLOCKDEVICE;
|
||||
fnode->ioctl = ioctl_vid;
|
||||
return fnode;
|
||||
}
|
||||
|
||||
static void finalize_graphics(uint16_t x, uint16_t y, uint16_t b) {
|
||||
lfb_resolution_x = x;
|
||||
lfb_resolution_y = y;
|
||||
lfb_resolution_b = b;
|
||||
}
|
||||
|
||||
uintptr_t lfb_get_address(void) {
|
||||
return (uintptr_t)lfb_vid_memory;
|
||||
fs_node_t * fb_device = lfb_video_device_create();
|
||||
vfs_mount("/dev/fb0", fb_device);
|
||||
}
|
||||
|
||||
/* Bochs support {{{ */
|
||||
uintptr_t current_scroll = 0;
|
||||
static uintptr_t current_scroll = 0;
|
||||
|
||||
void bochs_set_y_offset(uint16_t y) {
|
||||
static void bochs_set_y_offset(uint16_t y) {
|
||||
outports(0x1CE, 0x9);
|
||||
outports(0x1CF, y);
|
||||
current_scroll = y;
|
||||
}
|
||||
|
||||
uint16_t bochs_current_scroll(void) {
|
||||
static uint16_t bochs_current_scroll(void) {
|
||||
return current_scroll;
|
||||
}
|
||||
|
||||
void bochs_scan_pci(uint32_t device, uint16_t v, uint16_t d) {
|
||||
static void bochs_scan_pci(uint32_t device, uint16_t v, uint16_t d) {
|
||||
if (v == 0x1234 && d == 0x1111) {
|
||||
uintptr_t t = pci_read_field(device, PCI_BAR0, 4);
|
||||
if (t > 0) {
|
||||
@ -55,8 +100,9 @@ void bochs_scan_pci(uint32_t device, uint16_t v, uint16_t d) {
|
||||
}
|
||||
}
|
||||
|
||||
void graphics_install_bochs(uint16_t resolution_x, uint16_t resolution_y) {
|
||||
static void graphics_install_bochs(uint16_t resolution_x, uint16_t resolution_y) {
|
||||
debug_print(NOTICE, "Setting up BOCHS/QEMU graphics controller...");
|
||||
|
||||
outports(0x1CE, 0x00);
|
||||
uint16_t i = inports(0x1CF);
|
||||
if (i < 0xB0C0 || i > 0xB0C6) {
|
||||
@ -121,7 +167,7 @@ mem_found:
|
||||
|
||||
/* }}} end bochs support */
|
||||
|
||||
void graphics_install_preset(uint16_t w, uint16_t h) {
|
||||
static void graphics_install_preset(uint16_t w, uint16_t h) {
|
||||
debug_print(NOTICE, "Graphics were pre-configured (thanks, bootloader!), locating video memory...");
|
||||
uint16_t b = 32; /* If you are 24 bit, go away, we really do not support you. */
|
||||
|
||||
@ -179,4 +225,46 @@ mem_found:
|
||||
}
|
||||
}
|
||||
|
||||
static int init(void) {
|
||||
|
||||
if (mboot_ptr->vbe_mode_info) {
|
||||
lfb_vid_memory = (uint8_t *)((vbe_info_t *)(mboot_ptr->vbe_mode_info))->physbase;
|
||||
}
|
||||
|
||||
char * c;
|
||||
if ((c = args_value("vid"))) {
|
||||
debug_print(NOTICE, "Video mode requested: %s", c);
|
||||
|
||||
char * arg = strdup(c);
|
||||
char * argv[10];
|
||||
int argc = tokenize(arg, ",", argv);
|
||||
|
||||
uint16_t x, y;
|
||||
if (argc < 3) {
|
||||
x = 1024;
|
||||
y = 768;
|
||||
} else {
|
||||
x = atoi(argv[1]);
|
||||
y = atoi(argv[2]);
|
||||
}
|
||||
|
||||
if (!strcmp(argv[0], "qemu")) {
|
||||
/* Bochs / Qemu Video Device */
|
||||
graphics_install_bochs(x,y);
|
||||
} else if (!strcmp(argv[0],"preset")) {
|
||||
graphics_install_preset(x,y);
|
||||
} else {
|
||||
debug_print(WARNING, "Unrecognized video adapter: %s", argv[0]);
|
||||
}
|
||||
|
||||
free(arg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fini(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
MODULE_DEF(lfbvideo, init, fini);
|
@ -8,6 +8,7 @@
|
||||
#include <fs.h>
|
||||
#include <pipe.h>
|
||||
#include <logging.h>
|
||||
#include <args.h>
|
||||
#include <module.h>
|
||||
|
||||
#define SERIAL_PORT_A 0x3F8
|
||||
@ -18,8 +19,6 @@
|
||||
#define SERIAL_IRQ_AC 4
|
||||
#define SERIAL_IRQ_BD 3
|
||||
|
||||
#undef FORCE_DEBUG_OUTPUT_TO_SERIAL
|
||||
|
||||
static char serial_recv(int device);
|
||||
|
||||
static fs_node_t * _serial_port_a = NULL;
|
||||
@ -185,10 +184,12 @@ static int serial_mount_devices(void) {
|
||||
fs_node_t * ttyS3 = serial_device_create(SERIAL_PORT_D);
|
||||
vfs_mount("/dev/ttyS3", ttyS3);
|
||||
|
||||
#ifdef FORCE_DEBUG_OUTPUT_TO_SERIAL
|
||||
kprint_to_file = ttyS0;
|
||||
debug_level = 1;
|
||||
#endif
|
||||
char * c;
|
||||
if ((c = args_value("logtoserial"))) {
|
||||
kprint_to_file = ttyS0;
|
||||
debug_level = atoi(c);
|
||||
debug_print(NOTICE, "Serial logging enabled at level %d.", debug_level);
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
|
@ -6,8 +6,11 @@
|
||||
#include <syscall.h>
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include "graphics.h"
|
||||
#include "window.h"
|
||||
#include "../../kernel/include/video.h"
|
||||
|
||||
#define PNG_DEBUG 3
|
||||
#include <png.h>
|
||||
@ -42,11 +45,19 @@ void clearbuffer(gfx_context_t * ctx) {
|
||||
/* Deprecated */
|
||||
gfx_context_t * init_graphics_fullscreen() {
|
||||
gfx_context_t * out = malloc(sizeof(gfx_context_t));
|
||||
out->width = syscall_getgraphicswidth();
|
||||
out->height = syscall_getgraphicsheight();
|
||||
out->depth = syscall_getgraphicsdepth();
|
||||
|
||||
int fd = open("/dev/fb0", O_RDONLY);
|
||||
if (fd < 0) {
|
||||
/* oh shit */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ioctl(fd, IO_VID_WIDTH, &out->width);
|
||||
ioctl(fd, IO_VID_HEIGHT, &out->height);
|
||||
ioctl(fd, IO_VID_DEPTH, &out->depth);
|
||||
ioctl(fd, IO_VID_ADDR, &out->buffer);
|
||||
|
||||
out->size = GFX_H(out) * GFX_W(out) * GFX_B(out);
|
||||
out->buffer = (void *)syscall_getgraphicsaddress();
|
||||
out->backbuffer = out->buffer;
|
||||
return out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user