@@ -30,7 +30,6 @@ global_asm!(include_str!("stage_1.s"));
30
30
global_asm ! ( include_str!( "stage_2.s" ) ) ;
31
31
global_asm ! ( include_str!( "e820.s" ) ) ;
32
32
global_asm ! ( include_str!( "stage_3.s" ) ) ;
33
- global_asm ! ( include_str!( "stage_4.s" ) ) ;
34
33
global_asm ! ( include_str!( "context_switch.s" ) ) ;
35
34
36
35
#[ cfg( feature = "vga_320x200" ) ]
@@ -63,8 +62,44 @@ impl IdentityMappedAddr {
63
62
}
64
63
}
65
64
65
+ // Symbols defined in `linker.ld`
66
+ extern {
67
+ static mmap_ent: usize ;
68
+ static _memory_map: usize ;
69
+ static _kib_kernel_size: usize ;
70
+ static __page_table_start: usize ;
71
+ static __page_table_end: usize ;
72
+ static __bootloader_end: usize ;
73
+ static __bootloader_start: usize ;
74
+ }
75
+
66
76
#[ no_mangle]
67
- pub extern "C" fn load_elf (
77
+ pub unsafe extern "C" fn stage_4 ( ) -> ! {
78
+ asm ! ( "mov bx, 0x0" :: :: "intel" ) ;
79
+ asm ! ( "mov ss, bx" :: :: "intel" ) ; // Set stack segment
80
+
81
+ let kernel_start = 0x400000 ;
82
+ let kernel_size = _kib_kernel_size as u64 ;
83
+ let memory_map_addr = & _memory_map as * const _ as u64 ;
84
+ let memory_map_entry_count = ( mmap_ent & 0xff ) as u64 ; // Extract lower 8 bits
85
+ let page_table_start = & __page_table_start as * const _ as u64 ;
86
+ let page_table_end = & __page_table_end as * const _ as u64 ;
87
+ let bootloader_start = & __bootloader_start as * const _ as u64 ;
88
+ let bootloader_end = & __bootloader_end as * const _ as u64 ;
89
+
90
+ load_elf (
91
+ IdentityMappedAddr ( PhysAddr :: new ( kernel_start) ) ,
92
+ kernel_size,
93
+ VirtAddr :: new ( memory_map_addr) ,
94
+ memory_map_entry_count,
95
+ PhysAddr :: new ( page_table_start) ,
96
+ PhysAddr :: new ( page_table_end) ,
97
+ PhysAddr :: new ( bootloader_start) ,
98
+ PhysAddr :: new ( bootloader_end) ,
99
+ )
100
+ }
101
+
102
+ fn load_elf (
68
103
kernel_start : IdentityMappedAddr ,
69
104
kernel_size : u64 ,
70
105
memory_map_addr : VirtAddr ,
0 commit comments