diff options
author | dzwdz | 2022-08-06 00:12:51 +0200 |
---|---|---|
committer | dzwdz | 2022-08-06 00:12:51 +0200 |
commit | 03c6f3cf458c89df17b02557cd232f9cde73ed54 (patch) | |
tree | a89076307f32d9df6eec550f175accaa73d72408 /src/kernel/arch | |
parent | 641b857dcfe1cfca625fbd75646b743142a9069c (diff) |
make snprintf shared; dynamic resolution support
Diffstat (limited to 'src/kernel/arch')
-rw-r--r-- | src/kernel/arch/amd64/boot.c | 1 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/video.c | 21 | ||||
-rw-r--r-- | src/kernel/arch/amd64/driver/video.h | 1 | ||||
-rw-r--r-- | src/kernel/arch/amd64/multiboot.s | 4 |
4 files changed, 18 insertions, 9 deletions
diff --git a/src/kernel/arch/amd64/boot.c b/src/kernel/arch/amd64/boot.c index 570cebb..2707223 100644 --- a/src/kernel/arch/amd64/boot.c +++ b/src/kernel/arch/amd64/boot.c @@ -52,6 +52,7 @@ void kmain_early(struct multiboot_info *multiboot) { vid.width = multiboot->framebuffer_width; vid.height = multiboot->framebuffer_height; vid.bpp = multiboot->framebuffer_bpp; + vid.size = vid.pitch * vid.height; kprintf("framebuffer at 0x%x, %ux%u bpp %u\n", vid.b, vid.width, vid.height, vid.bpp); video_init(vid); diff --git a/src/kernel/arch/amd64/driver/video.c b/src/kernel/arch/amd64/driver/video.c index 2d1ac03..d22adc4 100644 --- a/src/kernel/arch/amd64/driver/video.c +++ b/src/kernel/arch/amd64/driver/video.c @@ -5,8 +5,12 @@ #include <kernel/mem/virt.h> #include <kernel/panic.h> #include <kernel/vfs/request.h> +#include <shared/mem.h> +#include <shared/printf.h> static struct fb_info fb; +static char namebuf[64]; +static size_t namelen; enum { H_ROOT, @@ -16,9 +20,10 @@ enum { static int handle(struct vfs_request *req) { switch (req->type) { case VFSOP_OPEN: + if (!req->input.kern) panic_invalid_state(); if (req->input.len == 1) { return H_ROOT; - } else if (req->input.len == 2 && req->input.kern && req->input.buf_kern[1] == 'b') { + } else if (req->input.len == namelen + 1 && !memcmp(req->input.buf_kern + 1, namebuf, namelen)) { return H_FB; } else { return -1; @@ -26,26 +31,26 @@ static int handle(struct vfs_request *req) { case VFSOP_READ: if (req->id == H_ROOT) { - // TODO list available modes, e.g /640x480x24 - const char src[] = "b"; - return req_readcopy(req, src, sizeof src); + return req_readcopy(req, namebuf, namelen + 1); } else { - return req_readcopy(req, fb.b, fb.pitch * fb.height); + return req_readcopy(req, fb.b, fb.size); } case VFSOP_WRITE: if ((long)req->id != H_FB) { return -1; } - fs_normslice(&req->offset, &req->input.len, fb.pitch * fb.height, false); + fs_normslice(&req->offset, &req->input.len, fb.size, false); if (!virt_cpy_from(req->caller->pages, fb.b + req->offset, req->input.buf, req->input.len)) { - panic_invalid_state(); return -EFAULT; } return req->input.len; + case VFSOP_GETSIZE: + return fb.size; + default: return -1; } @@ -67,5 +72,7 @@ static bool is_ready(struct vfs_backend *self) { static struct vfs_backend backend = BACKEND_KERN(is_ready, accept); void video_init(struct fb_info fb_) { fb = fb_; + snprintf(namebuf, sizeof namebuf, "%ux%ux%u", fb.width, fb.height, fb.bpp); + namelen = strlen(namebuf); vfs_mount_root_register("/video", &backend); } diff --git a/src/kernel/arch/amd64/driver/video.h b/src/kernel/arch/amd64/driver/video.h index c1680c4..dfc1710 100644 --- a/src/kernel/arch/amd64/driver/video.h +++ b/src/kernel/arch/amd64/driver/video.h @@ -5,6 +5,7 @@ struct fb_info { char *b; uint32_t width, height; uint32_t pitch; /* width in bytes of a single scanline */ + size_t size; uint8_t bpp; }; diff --git a/src/kernel/arch/amd64/multiboot.s b/src/kernel/arch/amd64/multiboot.s index c809297..4af0cd0 100644 --- a/src/kernel/arch/amd64/multiboot.s +++ b/src/kernel/arch/amd64/multiboot.s @@ -15,6 +15,6 @@ multiboot_header: .skip 5 * 4 .long 0 - .long 640 - .long 480 .long 0 + .long 0 + .long 32 |