blob: c7e9842dbd157b2d14d643b416a29b99ecbac0f8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
% example_01.bc
%
% Very minimalistic demo. Writes a short message in text mode and lets you
% boot linux or start from local disk.
%
% Notes:
%
% General work flow:
% - this code is run during initialization and must leave either 'true'
% or 'false' on the top of stack (TOS)
%
% - it must define (at least) a callback function 'KeyEvent' that is
% called later from the bootloader whenever a key is pressed
%
% - 'KeyEvent' returns a status code telling the bootloader how to
% proceed (e.g. boot or wait for more input)
%
% Test with (from top level dir [/usr/share/gfxboot]) 'gfxtest -t example_01'.
%
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Some constants we probably need.
%
/true 0 0 eq def
/false 0 0 ne def
% pointer type
/t_ptr 12 def
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Convert integer to pointer.
%
% ( int1 -- ptr1 )
%
/cvp { t_ptr settype } def
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Clear VGA text screen.
%
% ( -- )
%
/clearscreen {
% text screen starts at 0xb8000, two bytes per char (value + attribute)
% typical size: 25 x 80
% write spaces + attribute 7 (= light gray on black)
0xb8000 2 0xb8000 160 25 mul add 1 sub {
cvp 0x0720 putword
} for
} def
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Write to VGA text screen.
%
% ( x y text -- )
%
/print {
exch 80 mul
rot add 2 mul 0xb8000 add cvp
exch { over exch putbyte 2 add } forall
pop
} def
% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
% Input event handling.
%
% ( key -- input_buffer menu_entry action )
%
% key
% bit 0-7 ascii
% bit 8-15 scan code
% bit 16-32 status bits (ctrl, shift...)
%
% action
% 0: ok, stay in input loop
% 1: switch to text mode (that is, continue with the non-gfxboot bootloader interface)
% >=2: boot
%
% Notes:
% - key = 0 indicates the bootloader timeout is up.
% - input_buffer is the command line that you would have normally entered in the bootloader.
% note that for syslinux it must start with the menu label string but not for grub
% - menu_entry is the number of the menu entry you want to boot
%
/KeyEvent {
/key exch def
% 'linux' & 'harddisk' are labels in our test bootloader config (created by 'gfxtest')
key 0xff and 'l' eq { "linux" 1 2 return } if
key 0xff and 'd' eq { "harddisk" 0 2 return } if
"" 0 0
} def
% clear screen
clearscreen
% write some message
10 12 "Press 'l' to start linux or 'd' to boot from disk." print
% say we're fine ('false' tells bootloader not to use gfxboot)
true
|