8
8
#[ cfg( not( target_os = "none" ) ) ]
9
9
compile_error ! ( "The bootloader crate must be compiled for the `x86_64-bootloader.json` target" ) ;
10
10
11
- use bootloader:: { binary:: SystemInfo , boot_info:: FrameBufferInfo } ;
11
+ use bootloader:: {
12
+ binary:: SystemInfo ,
13
+ boot_info:: { FrameBufferInfo , PixelFormat } ,
14
+ } ;
12
15
use core:: panic:: PanicInfo ;
13
16
use core:: slice;
14
17
use usize_conversions:: usize_from;
@@ -31,7 +34,9 @@ extern "C" {
31
34
static VBEModeInfo_xresolution : u16 ;
32
35
static VBEModeInfo_yresolution : u16 ;
33
36
static VBEModeInfo_bitsperpixel : u8 ;
34
- // TODO color values (e.g. RGB or BGR)
37
+ static VBEModeInfo_redfieldposition : u8 ;
38
+ static VBEModeInfo_greenfieldposition : u8 ;
39
+ static VBEModeInfo_bluefieldposition : u8 ;
35
40
}
36
41
37
42
// Symbols defined in `linker.ld`
@@ -116,6 +121,7 @@ fn bootloader_main(
116
121
}
117
122
118
123
let framebuffer_addr = PhysAddr :: new ( unsafe { VBEModeInfo_physbaseptr } . into ( ) ) ;
124
+ let mut error = None ;
119
125
let framebuffer_info = unsafe {
120
126
let framebuffer_size =
121
127
usize:: from ( VBEModeInfo_yresolution ) * usize:: from ( VBEModeInfo_bytesperscanline ) ;
@@ -127,9 +133,27 @@ fn bootloader_main(
127
133
VBEModeInfo_yresolution . into ( ) ,
128
134
bytes_per_pixel. into ( ) ,
129
135
( VBEModeInfo_bytesperscanline / u16:: from ( bytes_per_pixel) ) . into ( ) ,
136
+ match (
137
+ VBEModeInfo_redfieldposition ,
138
+ VBEModeInfo_greenfieldposition ,
139
+ VBEModeInfo_bluefieldposition ,
140
+ ) {
141
+ ( 0 , 8 , 16 ) => PixelFormat :: RGB ,
142
+ ( 16 , 8 , 0 ) => PixelFormat :: BGR ,
143
+ ( r, g, b) => {
144
+ error = Some ( ( "invalid rgb field positions" , r, g, b) ) ;
145
+ PixelFormat :: RGB // default to RBG so that we can print something
146
+ }
147
+ } ,
130
148
)
131
149
} ;
132
150
151
+ log:: info!( "BIOS boot" ) ;
152
+
153
+ if let Some ( ( msg, r, g, b) ) = error {
154
+ panic ! ( "{}: r: {}, g: {}, b: {}" , msg, r, g, b) ;
155
+ }
156
+
133
157
let page_tables = create_page_tables ( & mut frame_allocator) ;
134
158
135
159
let kernel = {
@@ -158,17 +182,18 @@ fn init_logger(
158
182
vertical_resolution : usize ,
159
183
bytes_per_pixel : usize ,
160
184
stride : usize ,
185
+ pixel_format : PixelFormat ,
161
186
) -> FrameBufferInfo {
162
187
let ptr = framebuffer_start. as_u64 ( ) as * mut u8 ;
163
188
let slice = unsafe { slice:: from_raw_parts_mut ( ptr, framebuffer_size) } ;
164
- slice . fill ( 0xff ) ;
189
+
165
190
let info = bootloader:: boot_info:: FrameBufferInfo {
166
191
byte_len : framebuffer_size,
167
192
horizontal_resolution,
168
193
vertical_resolution,
169
194
bytes_per_pixel,
170
195
stride,
171
- pixel_format : bootloader :: boot_info :: PixelFormat :: RGB , // TODO: don't hardcode
196
+ pixel_format,
172
197
} ;
173
198
174
199
bootloader:: binary:: init_logger ( slice, info) ;
0 commit comments