Some work here and there

This commit is contained in:
Łukasz Magiera 2016-08-17 22:40:11 +02:00
parent 65ea917720
commit 3619b03290
13 changed files with 4079 additions and 54 deletions

View File

@ -35,6 +35,8 @@ OUTNAME = lupi
debug: CFLAGS+= -g -DLOGGING -DDEBUG
debug: build
####
winexe: $(BUILD)$(OUTNAME)
cp $(BUILD)$(OUTNAME) $(BUILD)$(OUTNAME).exe
@ -48,6 +50,55 @@ win-build: build winexe
win-debug: LIBS+= -lws2_32 -lgdi32
win-debug: debug winexe
####
dependencies/v86:
cd dependencies; git clone https://github.com/magik6k/v86.git
dependencies/v86/build/libv86.js: dependencies/v86
cd dependencies/v86 && wget -P closure-compiler http://dl.google.com/closure-compiler/compiler-latest.zip
cd dependencies/v86 && unzip -d closure-compiler closure-compiler/compiler-latest.zip compiler.jar
cd dependencies/v86 && make build/libv86.js
$(BUILD)web: dependencies/v86/build/libv86.js
rm -rf bin/web; mkdir -p bin/web
web: iso bin/web
####
ISOKERNEL=linux-4.5.2
dependencies/$(ISOKERNEL).tar.xz:
cd dependencies && wget https://cdn.kernel.org/pub/linux/kernel/v4.x/$(ISOKERNEL).tar.xz
dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage: $(BUILD)lupi.cpio dependencies/$(ISOKERNEL).tar.xz
rm -rf dependencies/$(ISOKERNEL)/
cd dependencies && tar xf $(ISOKERNEL).tar.xz
cp src/iso/linux.config dependencies/$(ISOKERNEL)/.config
cd dependencies/$(ISOKERNEL)/ && make -j8
$(BUILD)lupi.cpio: $(BUILDDIRECTORIES) $(BUILD)$(OUTNAME) build
rm -rf $(BUILD)iso.init; mkdir -p $(BUILD)iso.init
mkdir -p bin/iso.init/sbin bin/iso.init/proc bin/iso.init/sys bin/iso.init/dev bin/iso.init/tmp
cp bin/lupi bin/iso.init/sbin/init
(cd bin/iso.init; find . | fakeroot cpio -o -H newc) > $@
$(BUILD)lupi.iso: dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage
rm -rf bin/iso.dir; mkdir -p bin/iso.dir bin/iso.dir/boot
cp $(BUILD)lupi.cpio bin/iso.dir/boot/lupi.img
cp dependencies/$(ISOKERNEL)/arch/x86/boot/bzImage bin/iso.dir/boot/vmlinuz
cp src/iso/isolinux.cfg bin/iso.dir/isolinux.cfg
mkdir -p bin/iso.dir/syslinux bin/iso.dir/sbin
cp bin/lupi bin/iso.dir/sbin/init
cp /usr/lib/syslinux/bios/{isolinux.bin,ldlinux.c32,isohdpfx.bin} bin/iso.dir/syslinux/
mkisofs -o bin/lupi.iso -b syslinux/isolinux.bin -c syslinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table bin/iso.dir
iso: PREFIX?=i486-linux-musl
iso: build $(BUILD)lupi.iso
####
$(BUILDDIRECTORIES):
mkdir -p $@
@ -81,4 +132,4 @@ smallclean:
# Other
.PHONY: debug clean cleanresourcues resources build smallclean all
.PHONY: web iso debug clean cleanresourcues resources build smallclean all

View File

@ -34,6 +34,11 @@ int event_pull(int timeout);
#ifdef _WIN32
void winapigpu_init(lua_State* L);
#define WIN32
#include <event2/event.h>
#include <event2/event_struct.h>
void handleWinevent(evutil_socket_t fd, short what, void *eventc);
#undef WIN32
#endif
#endif

View File

@ -24,46 +24,7 @@ struct event_base *base;
struct event stdinEvent;
int nevt = 0;
#ifdef _WIN32
struct event winEvent;
evutil_socket_t pfd[2] = {0,0};
void pokeWinEvt(char ch) {
send(pfd[1], &ch, 1, 0);
}
static void handleWinevent(evutil_socket_t fd, short what, void *ptr) {
if(what != EV_READ) return;
char buf;
int r = recv(fd, &buf, 1, 0); /* TODO: Wide chars? */
if(r > 0) {
logi(buf);
logn(" < win char");
lua_State* L = getL();
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_down");
lua_pushstring(L, "TODO:SetThisUuid");/* Also in textgpu.lua */
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");
lua_call(L, 5, 0);
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_up");
lua_pushstring(L, "TODO:SetThisUuid");
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");
lua_call(L, 5, 0);
nevt += 2;
}
}
#endif
static void handleStdin(evutil_socket_t fd, short what, void *ptr) {
static void handleStdin(evutil_socket_t fd, short what, void *eventc) {
char buf;
if(what != EV_READ) return;
@ -88,11 +49,14 @@ static void handleStdin(evutil_socket_t fd, short what, void *ptr) {
lua_pushstring(L, "root");
lua_call(L, 5, 0);
nevt += 2;
*((int*) eventc) += 2;
}
}
#ifdef _WIN32
extern evutil_socket_t winInputPipe[2]; //TODO: make it nicer
struct event winEvent;
#endif
void event_prepare() {
struct event_config* cfg = event_config_new();
@ -100,12 +64,12 @@ void event_prepare() {
base = event_base_new_with_config(cfg);
evutil_make_socket_nonblocking(STDIN_FILENO);
event_assign(&stdinEvent, base, STDIN_FILENO, EV_READ, handleStdin, NULL);
event_assign(&stdinEvent, base, STDIN_FILENO, EV_READ, handleStdin, &nevt);
#ifdef _WIN32
evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, pfd);
evutil_make_socket_nonblocking(pfd[0]);
event_assign(&winEvent, base, pfd[0], EV_READ, handleWinevent, NULL);
evutil_socketpair(LOCAL_SOCKETPAIR_AF, SOCK_STREAM, 0, winInputPipe);
evutil_make_socket_nonblocking(winInputPipe[0]);
event_assign(&winEvent, base, winInputPipe[0], EV_READ, handleWinevent, &nevt);
#endif
}

45
src/c/event/winevent.c Normal file
View File

@ -0,0 +1,45 @@
#include "lupi.h"
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#ifdef _WIN32
#define WIN32
#include <event2/event.h>
#include <event2/event_struct.h>
evutil_socket_t winInputPipe[2] = {0,0};
void pokeWinEvt(char ch) {
send(winInputPipe[1], &ch, 1, 0);
}
void handleWinevent(evutil_socket_t fd, short what, void *eventc) {
if(what != EV_READ) return;
char buf;
int r = recv(fd, &buf, 1, 0); /* TODO: Wide chars? */
if(r > 0) {
lua_State* L = getL();
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_down");
lua_pushstring(L, "TODO:SetThisUuid");/* Also in textgpu.lua */
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");
lua_call(L, 5, 0);
lua_getglobal(L, "pushEvent");
lua_pushstring(L, "key_up");
lua_pushstring(L, "TODO:SetThisUuid");
lua_pushnumber(L, buf);
lua_pushnumber(L, -1);
lua_pushstring(L, "root");
lua_call(L, 5, 0);
*((int*) eventc) += 2;
}
}
#endif

View File

@ -448,6 +448,8 @@ void fb_start(lua_State *L) {
{"getBackground", l_fb_getbg},
{"getForeground", l_fb_getfg},
{"get", l_fb_get},
{"getfg", l_fb_getfg},
{"getbg", l_fb_getbg},
{"getNearest", l_get_nearest},
#endif
{"isReady", l_fb_ready},
@ -475,7 +477,7 @@ void fb_start(lua_State *L) {
return;
}
fb_vinfo.bits_per_pixel = 16;
fb_vinfo.bits_per_pixel = 32;
if (fb_rot == 1 || fb_rot == 3) {
fb_cw = fb_vinfo.yres / 8;
fb_ch = fb_vinfo.xres / 16;

View File

@ -89,11 +89,14 @@ LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
break;
case WM_CHAR:
//case WM_UNICHAR:
case WM_UNICHAR:
//case WM_KEYUP:
//case WM_KEYDOWN:
case WM_KEYDOWN: {
logi(wParam);
logn("");
pokeWinEvt(wParam);
break;
}
case WM_CREATE:
logn("win: Create");
screenbb = (uchar*) calloc(RES_X * RES_Y, BYPP);
@ -159,7 +162,7 @@ void* winapigpu_events(void* ign) {
MSG Msg;
while(GetMessage(&Msg, NULL, 0, 0) > 0) {
TranslateMessage(&Msg);
//TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
logn("winapi quit!!");

View File

@ -4,12 +4,18 @@
#include <sys/mount.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/statvfs.h>
#include <sys/mount.h>
void lupi_init() {
if(getpid() == 1) {
mount(NULL, "/sys", "sysfs", 0, NULL);
mount(NULL, "/proc", "procfs", 0, NULL);
}
struct statvfs fsstat;
statvfs("/", &fsstat);
printf("Filesystem / RO status: %X\n",fsstat.f_flag & MS_RDONLY);
}
#else
void lupi_init() {

6
src/iso/isolinux.cfg Normal file
View File

@ -0,0 +1,6 @@
prompt 0
default 1
LABEL 1
LINUX boot/vmlinuz
INITRD boot/lupi.img

3911
src/iso/linux.config Normal file

File diff suppressed because it is too large Load Diff

View File

@ -106,7 +106,7 @@ function fbgpu.start()
function gpu.get(x, y)
checkArg(1, x, "number")
checkArg(2, y, "number")
return utf8.char(fb.get(x-1, y-1))
return utf8.char(fb.get(x-1, y-1)), mapping[fb.getfg(x-1, y-1)], mapping[fb.getbg(x-1, y-1)]
end
function gpu.set(x, y, value, vertical)
checkArg(1, x, "number")

View File

@ -1,6 +1,7 @@
local gpudetect = {}
local function tryText()
lprint("Trying text-mode gpu")
loadModule("textgpu")
local textgpuAddr, tgfail = modules.textgpu.start()
if not textgpuAddr then
@ -11,6 +12,7 @@ local function tryText()
end
local function tryFb()
lprint("Trying framebuffer-mode gpu")
if framebuffer.isReady() then
loadModule("fbgpu")
modules.fbgpu.start()

View File

@ -121,8 +121,8 @@ function textgpu.start()
function gpu.get(x, y)
checkArg(1, x, "number")
checkArg(2, y, "number")
--FIXME: ASAP: Implement
return " "
return tbuffer[y]:sub(x,x), mapping[fbuffer[y]:sub(x,x)], mapping[bbuffer[y]:sub(x,x)]
end
function gpu.set(x, y, value, vertical)
checkArg(1, x, "number")

30
src/web/index.html Normal file
View File

@ -0,0 +1,30 @@
<!doctype html>
<title>LuPI Web</title>
<script src="libv86.js"></script>
<script>
"use strict";
window.onload = function()
{
var emulator = window.emulator = new V86Starter({
memory_size: 64 * 1024 * 1024,
vga_memory_size: 8 * 1024 * 1024,
screen_container: document.getElementById("screen_container"),
bios: {
url: "seabios.bin",
},
vga_bios: {
url: "bios/vgabios.bin",
},
cdrom: {
url: "lupi.iso",
},
autostart: true,
});
}
</script>
<div id="screen_container">
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
<canvas style="display: none"></canvas>
</div>