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/amd64/driver/video.c | |
parent | 641b857dcfe1cfca625fbd75646b743142a9069c (diff) |
make snprintf shared; dynamic resolution support
Diffstat (limited to 'src/kernel/arch/amd64/driver/video.c')
-rw-r--r-- | src/kernel/arch/amd64/driver/video.c | 21 |
1 files changed, 14 insertions, 7 deletions
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); } |