@@ -3,26 +3,28 @@ use core::fmt::{Debug, Formatter};
3
3
4
4
/// This tag indicates to the kernel what boot module was loaded along with
5
5
/// the kernel image, and where it can be found.
6
- #[ derive( Clone , Copy , Debug ) ]
6
+ #[ derive( Clone , Copy ) ]
7
7
#[ repr( C , packed) ] // only repr(C) would add unwanted padding near name_byte.
8
8
pub struct ModuleTag {
9
9
typ : u32 ,
10
10
size : u32 ,
11
11
mod_start : u32 ,
12
12
mod_end : u32 ,
13
- name_byte : u8 ,
13
+ /// Begin of the command line string.
14
+ cmdline_str : u8 ,
14
15
}
15
16
16
17
impl ModuleTag {
17
- // The multiboot specification defines the module str
18
- // as valid utf-8, therefore this function produces
19
- // defined behavior
20
- /// Get the name of the module.
21
- pub fn name ( & self ) -> & str {
18
+ // The multiboot specification defines the module str as valid utf-8 (zero terminated string),
19
+ // therefore this function produces defined behavior
20
+ /// Get the cmdline of the module. If the GRUB configuration contains
21
+ /// `module2 /foobar/some_boot_module --test cmdline-option`, then this method
22
+ /// will return `--test cmdline-option`.
23
+ pub fn cmdline ( & self ) -> & str {
22
24
use core:: { mem, slice, str} ;
23
25
let strlen = self . size as usize - mem:: size_of :: < ModuleTag > ( ) ;
24
26
unsafe {
25
- str:: from_utf8_unchecked ( slice:: from_raw_parts ( & self . name_byte as * const u8 , strlen) )
27
+ str:: from_utf8_unchecked ( slice:: from_raw_parts ( & self . cmdline_str as * const u8 , strlen) )
26
28
}
27
29
}
28
30
@@ -35,6 +37,24 @@ impl ModuleTag {
35
37
pub fn end_address ( & self ) -> u32 {
36
38
self . mod_end
37
39
}
40
+
41
+ /// The size of the module/the BLOB in memory.
42
+ pub fn module_size ( & self ) -> u32 {
43
+ self . mod_end - self . mod_start
44
+ }
45
+ }
46
+
47
+ impl Debug for ModuleTag {
48
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> core:: fmt:: Result {
49
+ f. debug_struct ( "ModuleTag" )
50
+ . field ( "type" , & self . typ )
51
+ . field ( "size (tag)" , & self . size )
52
+ . field ( "size (module)" , & ( self . module_size ( ) ) )
53
+ . field ( "mod_start" , & ( self . mod_start as * const usize ) )
54
+ . field ( "mod_end" , & ( self . mod_end as * const usize ) )
55
+ . field ( "cmdline" , & self . cmdline ( ) )
56
+ . finish ( )
57
+ }
38
58
}
39
59
40
60
pub fn module_iter ( iter : TagIter ) -> ModuleIter {
0 commit comments