Skip to content

Commit

Permalink
initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
wfeldt committed Mar 28, 2021
0 parents commit 7c48269
Show file tree
Hide file tree
Showing 629 changed files with 160,422 additions and 0 deletions.
674 changes: 674 additions & 0 deletions COPYING

Large diffs are not rendered by default.

112 changes: 112 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
GIT2LOG := $(shell if [ -x ./git2log ] ; then echo ./git2log --update ; else echo true ; fi)
GITDEPS := $(shell [ -d .git ] && echo .git/HEAD .git/refs/heads .git/refs/tags)
VERSION := $(shell $(GIT2LOG) --version VERSION ; cat VERSION)
BRANCH := $(shell git branch | perl -ne 'print $$_ if s/^\*\s*//')
PREFIX := gfxboot2-$(VERSION)

ifdef 32BIT
OPT_32BIT = -m32
endif

CC = gcc
CFLAGS = -g -O2 $(OPT_32BIT) -I. -Wall -Wno-pointer-sign -Wsign-conversion -Wsign-compare
LDFLAGS = $(OPT_32BIT)

GFXBOOT_LIB_SRC = gfxboot.c gfxboot_main.c \
gfxboot_array.c gfxboot_canvas.c gfxboot_draw.c gfxboot_font.c gfxboot_hash.c gfxboot_context.c \
gfxboot_lib.c gfxboot_malloc.c gfxboot_gstate.c gfxboot_jpeg.c \
gfxboot_mem.c gfxboot_num.c gfxboot_obj.c gfxboot_olist.c gfxboot_prim.c gfxboot_debug.c
GFXBOOT_LIB_OBJ = $(GFXBOOT_LIB_SRC:.c=.o)

GFXBOOT_BIN_SRC = gfxboot-compile.c gfxboot-x11.c
GFXBOOT_BIN_OBJ = $(GFXBOOT_BIN_SRC:.c=.o)

GFXBOOT_HEADER = gfxboot.h vocabulary.h

GRUB_MODULE_BIOS = $(shell . ./config_vars ; echo $$grub_module_bios)
GRUB_MODULE_EFI = $(shell . ./config_vars ; echo $$grub_module_efi)
GRUB_FILES = $(shell . ./config_vars ; echo $$grub_files)
GRUB_ISO = $(shell . ./config_vars ; echo $$grub_iso)

ifneq "$(vm)" ""
VM = --$(vm)
endif

.PHONY: all grub-bios grub-efi grub-iso test-bios test-efi test-x11 archive clean tests

all: gfxboot-x11 gfxboot-compile gfxboot-font

changelog: $(GITDEPS)
$(GIT2LOG) --changelog changelog

doc: doc/reference.adoc

doc/reference.adoc: vocabulary.def gfxboot_prim.c doc/reference_template
./mk_reference vocabulary.def gfxboot_prim.c doc/reference_template $@

grub-bios: $(GRUB_MODULE_BIOS)

grub-efi: $(GRUB_MODULE_EFI)

grub-iso: $(GRUB_ISO)

test-bios: grub-iso
vm --cdrom $(GRUB_ISO) $(VM) --serial

test-efi: grub-iso
vm --cdrom $(GRUB_ISO) $(VM) --serial --efi

test-x11: gfxboot-x11 gfxboot-compile
./mk_x11_test
./gfxboot-x11 x11

test-cons: gfxboot-x11 gfxboot-compile
./mk_x11_test
./gfxboot-x11 --no-x11 --file - x11

test-console: gfxboot-x11 gfxboot-compile
./mk_x11_test
./gfxboot-x11 --no-x11 --file - x11

vocabulary.h: vocabulary.def types.def
./mk_vocabulary vocabulary.def types.def $@

$(GFXBOOT_LIB_OBJ): %.o: %.c $(GFXBOOT_HEADER)
$(CC) -c $(CFLAGS) -ffreestanding $<

$(GFXBOOT_BIN_OBJ): %.o: %.c $(GFXBOOT_HEADER)
$(CC) -c $(CFLAGS) $<

gfxboot-x11: gfxboot-x11.o $(GFXBOOT_LIB_OBJ)
$(CC) $< $(GFXBOOT_LIB_OBJ) $(LDFLAGS) -lX11 -o $@

gfxboot-compile: gfxboot-compile.o
$(CC) $< $(LDFLAGS) -o $@

gfxboot-font: gfxboot-font.c
$(CC) $(CFLAGS) -I /usr/include/freetype2 -lfreetype $< -o $@

$(GRUB_MODULE_BIOS): $(GRUB_FILES)
./grub_build --bios

$(GRUB_MODULE_EFI): $(GRUB_FILES)
./grub_build --efi

$(GRUB_ISO): $(GRUB_MODULE_BIOS) $(GRUB_MODULE_EFI)
./mk_grub_test

tests: gfxboot-x11 gfxboot-compile
@./run_tests

archive: changelog
@if [ ! -d .git ] ; then echo no git repo ; false ; fi
mkdir -p package
git archive --prefix=$(PREFIX)/ $(BRANCH) > package/$(PREFIX).tar
tar -r -f package/$(PREFIX).tar --mode=0664 --owner=root --group=root --mtime="`git show -s --format=%ci`" --transform='s:^:$(PREFIX)/:' VERSION changelog
xz -f package/$(PREFIX).tar

clean:
rm -f changelog VERSION vocabulary.h
rm -f $(GRUB_ISO) screenlog.0 *~ *.o gfxboot-{x11,font,compile} sample *.log files/*~ *.gc doc/*~
rm -f tests/*~ tests/*/{*.log,*~,*.gc,gc.log.ref,opt*.log.ref}
rm -rf x11 grub package
91 changes: 91 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
= gfxboot2

A graphical interface to bootloaders.

__This is still in a very early stage.__

It's essentially a rework of https://github.com/openSUSE/gfxboot[gfxboot]
but written in C.

The implemented scripting language is again a
https://en.wikipedia.org/wiki/Stack-oriented_programming[stack-based language] - similar
to what gfxboot uses but with integrated memory management and a hash data type.

=== Status

__The code is not yet ready to be used.__

The scripting language is basically implemented, including the graphics primitves.

The connection to `grub` is still a bit awkward. The patches extend grub to
expose a link to the graphics framebuffer.

This is not strictly needed. gfxboot does never read the video memory.
An`update` function that can update a rectangular screen area would suffice.

AFAICS grub does not exactly have that. There is
`doublebuf_blit_update_screen` in
https://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/video/fb/video_fb.c[grub-core/video/fb/video_fb.c],
though. But this updates continuous memory ranges, not rectangular areas.

=== A first look

.A cat
image::doc/screen_01.png[A cat]

.The source code
[%collapsible]
====
[source]
----
/cfont getconsolegstate getfont def
/foo "foo.fnt" readfile newfont def
/bar "bar.fnt" readfile newfont def
/text "ABC 12345 xyz # * % & § öäüß €" def
/image gstate def
image "katze_800.jpg" readfile unpackimage setcanvas
0 0 setpos
image getgstate exch blt
0x90000000 setcolor
image dim fillrect
0xffff00 setcolor
getgstate cfont setfont
50 50 setpos "Some font samples" show
0x00ffffff setcolor
getgstate cfont setfont
50 100 setpos text show
getgstate bar setfont
50 130 setpos text show
getgstate foo setfont
50 180 setpos text show
----
====

The prompt in the lower part of the screen is the debug console.

=== Next steps

- get a basic boot menu working
- fine-tune language definition
- more systematic debug console
- add de-fragmentation to memory management
- work on documentation

=== Some documentation

For details check out the link:doc/reference.adoc#add[language reference].

To get started, read the link:doc/building.adoc#add[build instructions].

The code is covered by a link:doc/testing.adoc#add[test suite].

The link:doc/internals.adoc#add[binary format] is also documented.
18 changes: 18 additions & 0 deletions config_vars
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# this config file is sourced in build and test scripts

su="sw 0"

grub_root=~/g
grub_build=b
grub_dir="$grub_root/$grub_build"

grub_module=gfxboot
grub_files="gfxboot.c gfxboot.h gfxboot_*.c vocabulary.h"

grub_module_bios=$grub_dir/build/grub-core/$grub_module.mod
grub_module_efi=$grub_dir/build-efi/grub-core/$grub_module.mod

grub_iso_src=files/cd
grub_iso_dir=$PWD/grub
grub_iso=$PWD/grub.iso

46 changes: 46 additions & 0 deletions doc/building.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
== Prepare grub builds

=== check out grub2 package
osc co openSUSE:Factory/grub2
cd openSUSE:Factory/grub2

=== build it locally
osc build --clean --download-api-only standard x86_64

=== prepare $HOME/g and $HOME/g/b symlinks pointing to grub2 build directory
ln -snf $OBS_BUILD_DIR/obs-openSUSE:Factory-standard-grub2 ~/g
cd ~g
ln -snf .build.packages/BUILD/grub-2.04 b

=== apply gfxboot2 patches
cd ~g/b
patch -p1 < $GFXBOOT2_DIR/patches/grub-2.04.diff

== required packages

- mksusecd
- qemu
- vm (TBD)
- freetype2-devel
- libX11-devel

== building 32bit binaries
- packages
- glibc-devel-32bit
- freetype2-devel-32bit
- libX11-devel-32bit
- gcc-32bit

- run 'make 32BIT=1 ...'

== make targets
- (default target): build gfxboot tools: gfxboot-compile, gfxboot-font, gfxboot-x11
- tests: run test suite
- grub-bios: legacy grub
- grub-efi: efi grub
- grub-iso: build grub bootable iso
- test-x11: build & run x11 variant
- test-console: build & run text console variant (no gfx shown)
- test-bios: build & legacy boot iso with qemu
- test-efi: build & efi boot iso with qemu
- test-XXX builds use the files in the 'files' subdirectory - main.gs contains the main program
68 changes: 68 additions & 0 deletions doc/internals.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
== Internal data structures

=== Binary format

The binary code is encoded as follows:

1 opcode byte followed by 0 or more data bytes

[source]
----
opcode [data] ...
opcode [data] ...
...
opcode bits 0..3: type
opcode bits 4..7: arg
----

There are 2 variants of opcodes:

- the 1st decodes into type + signed/unsigned 64 bit value (arg1)
- the 2nd decodes into type + unsigned 32 bit value (arg1, the size of the
following byte array) + byte array (arg2)

The 1st group is for number-like data, the 2nd group for string-like data. Note that strings are not
zero-terminated.

[source]
----
if type < 5
# variant 1
if arg < 8
arg1 = arg
else # arg >= 8
arg1 = decode_num(arg - 7) # 1..8 bytes
# arg1 will be decoded as signed if type is 1 (integer), else unsigned
# (if signed, bit 7 of the last byte is the sign bit)
endif
else # type >= 5
# variant 2
if arg < 12
arg1 = arg
else # arg >= 12
arg1 = decode_num(arg - 11) # 1..4 bytes
# arg1 will always be decoded as unsigned
endif
arg2 = the following arg1 bytes # arg1 may be 0
endif
decode_num(n): read next n bytes as little-endian number
----

For type codes see `types.def`.

The file has to start with the magic byte sequence `0x75 0x51 0x12 0xa9 0x42 0x7a 0xad 0x60`.
(Which decodes as a 7 char long special comment.)

Sample decoded byte sequences:

[source]
----
# hex [type] decoded value
00 [nil] nil
51 [int] 5
81 ff [int] -1
37 61 62 63 [str] "abc"
c7 0e 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e [str] "abcdefghijklmn"
----
Loading

0 comments on commit 7c48269

Please sign in to comment.