Skip to content

Commit 7c48269

Browse files
committed
initial version
0 parents  commit 7c48269

File tree

629 files changed

+160422
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

629 files changed

+160422
-0
lines changed

COPYING

+674
Large diffs are not rendered by default.

Makefile

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
GIT2LOG := $(shell if [ -x ./git2log ] ; then echo ./git2log --update ; else echo true ; fi)
2+
GITDEPS := $(shell [ -d .git ] && echo .git/HEAD .git/refs/heads .git/refs/tags)
3+
VERSION := $(shell $(GIT2LOG) --version VERSION ; cat VERSION)
4+
BRANCH := $(shell git branch | perl -ne 'print $$_ if s/^\*\s*//')
5+
PREFIX := gfxboot2-$(VERSION)
6+
7+
ifdef 32BIT
8+
OPT_32BIT = -m32
9+
endif
10+
11+
CC = gcc
12+
CFLAGS = -g -O2 $(OPT_32BIT) -I. -Wall -Wno-pointer-sign -Wsign-conversion -Wsign-compare
13+
LDFLAGS = $(OPT_32BIT)
14+
15+
GFXBOOT_LIB_SRC = gfxboot.c gfxboot_main.c \
16+
gfxboot_array.c gfxboot_canvas.c gfxboot_draw.c gfxboot_font.c gfxboot_hash.c gfxboot_context.c \
17+
gfxboot_lib.c gfxboot_malloc.c gfxboot_gstate.c gfxboot_jpeg.c \
18+
gfxboot_mem.c gfxboot_num.c gfxboot_obj.c gfxboot_olist.c gfxboot_prim.c gfxboot_debug.c
19+
GFXBOOT_LIB_OBJ = $(GFXBOOT_LIB_SRC:.c=.o)
20+
21+
GFXBOOT_BIN_SRC = gfxboot-compile.c gfxboot-x11.c
22+
GFXBOOT_BIN_OBJ = $(GFXBOOT_BIN_SRC:.c=.o)
23+
24+
GFXBOOT_HEADER = gfxboot.h vocabulary.h
25+
26+
GRUB_MODULE_BIOS = $(shell . ./config_vars ; echo $$grub_module_bios)
27+
GRUB_MODULE_EFI = $(shell . ./config_vars ; echo $$grub_module_efi)
28+
GRUB_FILES = $(shell . ./config_vars ; echo $$grub_files)
29+
GRUB_ISO = $(shell . ./config_vars ; echo $$grub_iso)
30+
31+
ifneq "$(vm)" ""
32+
VM = --$(vm)
33+
endif
34+
35+
.PHONY: all grub-bios grub-efi grub-iso test-bios test-efi test-x11 archive clean tests
36+
37+
all: gfxboot-x11 gfxboot-compile gfxboot-font
38+
39+
changelog: $(GITDEPS)
40+
$(GIT2LOG) --changelog changelog
41+
42+
doc: doc/reference.adoc
43+
44+
doc/reference.adoc: vocabulary.def gfxboot_prim.c doc/reference_template
45+
./mk_reference vocabulary.def gfxboot_prim.c doc/reference_template $@
46+
47+
grub-bios: $(GRUB_MODULE_BIOS)
48+
49+
grub-efi: $(GRUB_MODULE_EFI)
50+
51+
grub-iso: $(GRUB_ISO)
52+
53+
test-bios: grub-iso
54+
vm --cdrom $(GRUB_ISO) $(VM) --serial
55+
56+
test-efi: grub-iso
57+
vm --cdrom $(GRUB_ISO) $(VM) --serial --efi
58+
59+
test-x11: gfxboot-x11 gfxboot-compile
60+
./mk_x11_test
61+
./gfxboot-x11 x11
62+
63+
test-cons: gfxboot-x11 gfxboot-compile
64+
./mk_x11_test
65+
./gfxboot-x11 --no-x11 --file - x11
66+
67+
test-console: gfxboot-x11 gfxboot-compile
68+
./mk_x11_test
69+
./gfxboot-x11 --no-x11 --file - x11
70+
71+
vocabulary.h: vocabulary.def types.def
72+
./mk_vocabulary vocabulary.def types.def $@
73+
74+
$(GFXBOOT_LIB_OBJ): %.o: %.c $(GFXBOOT_HEADER)
75+
$(CC) -c $(CFLAGS) -ffreestanding $<
76+
77+
$(GFXBOOT_BIN_OBJ): %.o: %.c $(GFXBOOT_HEADER)
78+
$(CC) -c $(CFLAGS) $<
79+
80+
gfxboot-x11: gfxboot-x11.o $(GFXBOOT_LIB_OBJ)
81+
$(CC) $< $(GFXBOOT_LIB_OBJ) $(LDFLAGS) -lX11 -o $@
82+
83+
gfxboot-compile: gfxboot-compile.o
84+
$(CC) $< $(LDFLAGS) -o $@
85+
86+
gfxboot-font: gfxboot-font.c
87+
$(CC) $(CFLAGS) -I /usr/include/freetype2 -lfreetype $< -o $@
88+
89+
$(GRUB_MODULE_BIOS): $(GRUB_FILES)
90+
./grub_build --bios
91+
92+
$(GRUB_MODULE_EFI): $(GRUB_FILES)
93+
./grub_build --efi
94+
95+
$(GRUB_ISO): $(GRUB_MODULE_BIOS) $(GRUB_MODULE_EFI)
96+
./mk_grub_test
97+
98+
tests: gfxboot-x11 gfxboot-compile
99+
@./run_tests
100+
101+
archive: changelog
102+
@if [ ! -d .git ] ; then echo no git repo ; false ; fi
103+
mkdir -p package
104+
git archive --prefix=$(PREFIX)/ $(BRANCH) > package/$(PREFIX).tar
105+
tar -r -f package/$(PREFIX).tar --mode=0664 --owner=root --group=root --mtime="`git show -s --format=%ci`" --transform='s:^:$(PREFIX)/:' VERSION changelog
106+
xz -f package/$(PREFIX).tar
107+
108+
clean:
109+
rm -f changelog VERSION vocabulary.h
110+
rm -f $(GRUB_ISO) screenlog.0 *~ *.o gfxboot-{x11,font,compile} sample *.log files/*~ *.gc doc/*~
111+
rm -f tests/*~ tests/*/{*.log,*~,*.gc,gc.log.ref,opt*.log.ref}
112+
rm -rf x11 grub package

README.adoc

+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
= gfxboot2
2+
3+
A graphical interface to bootloaders.
4+
5+
__This is still in a very early stage.__
6+
7+
It's essentially a rework of https://github.com/openSUSE/gfxboot[gfxboot]
8+
but written in C.
9+
10+
The implemented scripting language is again a
11+
https://en.wikipedia.org/wiki/Stack-oriented_programming[stack-based language] - similar
12+
to what gfxboot uses but with integrated memory management and a hash data type.
13+
14+
=== Status
15+
16+
__The code is not yet ready to be used.__
17+
18+
The scripting language is basically implemented, including the graphics primitves.
19+
20+
The connection to `grub` is still a bit awkward. The patches extend grub to
21+
expose a link to the graphics framebuffer.
22+
23+
This is not strictly needed. gfxboot does never read the video memory.
24+
An`update` function that can update a rectangular screen area would suffice.
25+
26+
AFAICS grub does not exactly have that. There is
27+
`doublebuf_blit_update_screen` in
28+
https://git.savannah.gnu.org/cgit/grub.git/tree/grub-core/video/fb/video_fb.c[grub-core/video/fb/video_fb.c],
29+
though. But this updates continuous memory ranges, not rectangular areas.
30+
31+
=== A first look
32+
33+
.A cat
34+
image::doc/screen_01.png[A cat]
35+
36+
.The source code
37+
[%collapsible]
38+
====
39+
[source]
40+
----
41+
/cfont getconsolegstate getfont def
42+
/foo "foo.fnt" readfile newfont def
43+
/bar "bar.fnt" readfile newfont def
44+
45+
/text "ABC 12345 xyz # * % & § öäüß €" def
46+
47+
/image gstate def
48+
image "katze_800.jpg" readfile unpackimage setcanvas
49+
50+
0 0 setpos
51+
image getgstate exch blt
52+
0x90000000 setcolor
53+
image dim fillrect
54+
55+
0xffff00 setcolor
56+
57+
getgstate cfont setfont
58+
50 50 setpos "Some font samples" show
59+
60+
0x00ffffff setcolor
61+
62+
getgstate cfont setfont
63+
50 100 setpos text show
64+
65+
getgstate bar setfont
66+
50 130 setpos text show
67+
68+
getgstate foo setfont
69+
50 180 setpos text show
70+
----
71+
====
72+
73+
The prompt in the lower part of the screen is the debug console.
74+
75+
=== Next steps
76+
77+
- get a basic boot menu working
78+
- fine-tune language definition
79+
- more systematic debug console
80+
- add de-fragmentation to memory management
81+
- work on documentation
82+
83+
=== Some documentation
84+
85+
For details check out the link:doc/reference.adoc#add[language reference].
86+
87+
To get started, read the link:doc/building.adoc#add[build instructions].
88+
89+
The code is covered by a link:doc/testing.adoc#add[test suite].
90+
91+
The link:doc/internals.adoc#add[binary format] is also documented.

config_vars

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# this config file is sourced in build and test scripts
2+
3+
su="sw 0"
4+
5+
grub_root=~/g
6+
grub_build=b
7+
grub_dir="$grub_root/$grub_build"
8+
9+
grub_module=gfxboot
10+
grub_files="gfxboot.c gfxboot.h gfxboot_*.c vocabulary.h"
11+
12+
grub_module_bios=$grub_dir/build/grub-core/$grub_module.mod
13+
grub_module_efi=$grub_dir/build-efi/grub-core/$grub_module.mod
14+
15+
grub_iso_src=files/cd
16+
grub_iso_dir=$PWD/grub
17+
grub_iso=$PWD/grub.iso
18+

doc/building.adoc

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
== Prepare grub builds
2+
3+
=== check out grub2 package
4+
osc co openSUSE:Factory/grub2
5+
cd openSUSE:Factory/grub2
6+
7+
=== build it locally
8+
osc build --clean --download-api-only standard x86_64
9+
10+
=== prepare $HOME/g and $HOME/g/b symlinks pointing to grub2 build directory
11+
ln -snf $OBS_BUILD_DIR/obs-openSUSE:Factory-standard-grub2 ~/g
12+
cd ~g
13+
ln -snf .build.packages/BUILD/grub-2.04 b
14+
15+
=== apply gfxboot2 patches
16+
cd ~g/b
17+
patch -p1 < $GFXBOOT2_DIR/patches/grub-2.04.diff
18+
19+
== required packages
20+
21+
- mksusecd
22+
- qemu
23+
- vm (TBD)
24+
- freetype2-devel
25+
- libX11-devel
26+
27+
== building 32bit binaries
28+
- packages
29+
- glibc-devel-32bit
30+
- freetype2-devel-32bit
31+
- libX11-devel-32bit
32+
- gcc-32bit
33+
34+
- run 'make 32BIT=1 ...'
35+
36+
== make targets
37+
- (default target): build gfxboot tools: gfxboot-compile, gfxboot-font, gfxboot-x11
38+
- tests: run test suite
39+
- grub-bios: legacy grub
40+
- grub-efi: efi grub
41+
- grub-iso: build grub bootable iso
42+
- test-x11: build & run x11 variant
43+
- test-console: build & run text console variant (no gfx shown)
44+
- test-bios: build & legacy boot iso with qemu
45+
- test-efi: build & efi boot iso with qemu
46+
- test-XXX builds use the files in the 'files' subdirectory - main.gs contains the main program

doc/internals.adoc

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
== Internal data structures
2+
3+
=== Binary format
4+
5+
The binary code is encoded as follows:
6+
7+
1 opcode byte followed by 0 or more data bytes
8+
9+
[source]
10+
----
11+
opcode [data] ...
12+
opcode [data] ...
13+
...
14+
15+
opcode bits 0..3: type
16+
opcode bits 4..7: arg
17+
----
18+
19+
There are 2 variants of opcodes:
20+
21+
- the 1st decodes into type + signed/unsigned 64 bit value (arg1)
22+
- the 2nd decodes into type + unsigned 32 bit value (arg1, the size of the
23+
following byte array) + byte array (arg2)
24+
25+
The 1st group is for number-like data, the 2nd group for string-like data. Note that strings are not
26+
zero-terminated.
27+
28+
[source]
29+
----
30+
if type < 5
31+
# variant 1
32+
if arg < 8
33+
arg1 = arg
34+
else # arg >= 8
35+
arg1 = decode_num(arg - 7) # 1..8 bytes
36+
# arg1 will be decoded as signed if type is 1 (integer), else unsigned
37+
# (if signed, bit 7 of the last byte is the sign bit)
38+
endif
39+
else # type >= 5
40+
# variant 2
41+
if arg < 12
42+
arg1 = arg
43+
else # arg >= 12
44+
arg1 = decode_num(arg - 11) # 1..4 bytes
45+
# arg1 will always be decoded as unsigned
46+
endif
47+
arg2 = the following arg1 bytes # arg1 may be 0
48+
endif
49+
50+
decode_num(n): read next n bytes as little-endian number
51+
----
52+
53+
For type codes see `types.def`.
54+
55+
The file has to start with the magic byte sequence `0x75 0x51 0x12 0xa9 0x42 0x7a 0xad 0x60`.
56+
(Which decodes as a 7 char long special comment.)
57+
58+
Sample decoded byte sequences:
59+
60+
[source]
61+
----
62+
# hex [type] decoded value
63+
00 [nil] nil
64+
51 [int] 5
65+
81 ff [int] -1
66+
37 61 62 63 [str] "abc"
67+
c7 0e 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e [str] "abcdefghijklmn"
68+
----

0 commit comments

Comments
 (0)