1
- use crate :: { bios_enums:: PacketSize , first_stage } ;
1
+ use crate :: bios_enums:: PacketSize ;
2
2
use core:: arch:: asm;
3
3
4
4
#[ repr( C , packed) ]
@@ -13,86 +13,53 @@ pub struct DiskAddressPacket {
13
13
num_of_blocks : u16 ,
14
14
15
15
/// Which address in memory to save the data
16
- transfer_buffer : u32 ,
16
+ memory_buffer : u16 ,
17
+
18
+ /// Memory segment for the address
19
+ segment : u16 ,
17
20
18
21
/// The LBA address of the first sector
19
22
abs_block_num : u64 ,
20
23
}
21
24
22
- #[ repr( C , packed) ]
23
- pub struct PartitionTableEntry {
24
- /// Boot indicator bit flag: 0 = no, 0x80 = bootable (or "active").
25
- pub bootable : u8 ,
26
-
27
- /// Starting head of the partition.
28
- pub start_head : u8 ,
29
-
30
- /// Bits 0-5 are the starting sector.
31
- /// Bits 6-16 are the starting cylinder.
32
- pub sector_cylider_start : u16 ,
33
-
34
- /// SystemID.
35
- pub system_id : u8 ,
36
-
37
- /// Ending head of the partition.
38
- pub end_head : u8 ,
39
-
40
- /// Bits 0-5 are the ending sector.
41
- /// Bits 6-16 are the ending cylinder.
42
- pub sector_cylinder_head : u16 ,
43
-
44
- /// Relative Sector (to start of partition -- also equals the partition's starting LBA value)
45
- pub relative_sector : u32 ,
46
-
47
- /// Total Sectors in partition
48
- pub total_sectors : u32 ,
49
- }
50
-
51
- pub struct MasterBootRecord {
52
- pub entries : [ PartitionTableEntry ; 4 ] ,
53
- }
54
-
55
25
impl DiskAddressPacket {
56
-
57
- first_stage ! {
58
26
59
- pub fn new(
60
- packet_size: PacketSize ,
61
- num_of_blocks: u16 ,
62
- transfer_buffer: u32 ,
63
- abs_block_num: u64 ,
64
- ) -> Self {
65
- Self {
66
- packet_size: packet_size as u8 ,
67
- zero: 0 ,
68
- num_of_blocks,
69
- transfer_buffer,
70
- abs_block_num,
71
- }
72
- }
73
-
74
- pub fn load( & self ) {
75
- let self_address = self as * const Self as u32 ;
76
- unsafe {
77
- asm!(
78
- "push si" , // si register is required for llvm it's content needs to be saved
79
- "mov si, {3:x}" ,
80
- "mov ah, {0}" ,
81
- "mov dl, {1}" ,
82
- "int {2}" ,
83
- "pop si" ,
84
- const 0x42u8 ,
85
- const 0x80u8 ,
86
- const 0x13u8 ,
87
- in( reg) self_address,
88
- )
89
- }
27
+ #[ unsafe( link_section = ".first_stage" ) ]
28
+ pub const fn new (
29
+ num_of_blocks : u16 ,
30
+ memory_buffer : u16 ,
31
+ segment : u16 ,
32
+ abs_block_num : u64 ,
33
+ ) -> Self {
34
+ Self {
35
+ packet_size : 0x10 as u8 ,
36
+ zero : 0 ,
37
+ num_of_blocks,
38
+ memory_buffer,
39
+ segment,
40
+ abs_block_num,
90
41
}
91
-
92
42
}
93
43
94
- pub fn chs_to_lba ( ) {
95
- todo ! ( )
44
+ #[ unsafe( link_section = ".first_stage" ) ]
45
+ pub fn load ( & self ) {
46
+ unsafe {
47
+ asm ! (
48
+ "push si" , // si register is required for llvm it's content needs to be saved
49
+ "mov si, {3:x}" ,
50
+ "mov ah, {0}" ,
51
+ "mov dl, {1}" ,
52
+ "int {2}" ,
53
+ "pop si" ,
54
+ const 0x42u8 ,
55
+ const 0x80u8 ,
56
+ const 0x13u8 ,
57
+ in( reg) self as * const Self as u32 ,
58
+ )
59
+ }
96
60
}
61
+ }
97
62
63
+ pub fn chs_to_lba ( ) {
64
+ todo ! ( )
98
65
}
0 commit comments