@@ -39,7 +39,7 @@ pub mod serial;
39
39
40
40
const PAGE_SIZE : u64 = 4096 ;
41
41
42
- /// Initialize a text-based logger using the given pixel-based framebuffer as output.
42
+ /// Initialize a text-based logger using the given pixel-based framebuffer as output.
43
43
pub fn init_logger (
44
44
framebuffer : & ' static mut [ u8 ] ,
45
45
info : FrameBufferInfo ,
@@ -195,10 +195,10 @@ where
195
195
enable_write_protect_bit ( ) ;
196
196
197
197
let config = kernel. config ;
198
- let kernel_slice_start = kernel. start_address as u64 ;
198
+ let kernel_slice_start = PhysAddr :: new ( kernel. start_address as _ ) ;
199
199
let kernel_slice_len = u64:: try_from ( kernel. len ) . unwrap ( ) ;
200
200
201
- let ( entry_point, tls_template) = load_kernel:: load_kernel (
201
+ let ( kernel_image_offset , entry_point, tls_template) = load_kernel:: load_kernel (
202
202
kernel,
203
203
kernel_page_table,
204
204
frame_allocator,
@@ -402,6 +402,8 @@ where
402
402
403
403
kernel_slice_start,
404
404
kernel_slice_len,
405
+ kernel_image_offset,
406
+
405
407
ramdisk_slice_start,
406
408
ramdisk_slice_len,
407
409
}
@@ -426,9 +428,11 @@ pub struct Mappings {
426
428
pub tls_template : Option < TlsTemplate > ,
427
429
428
430
/// Start address of the kernel slice allocation in memory.
429
- pub kernel_slice_start : u64 ,
431
+ pub kernel_slice_start : PhysAddr ,
430
432
/// Size of the kernel slice allocation in memory.
431
433
pub kernel_slice_len : u64 ,
434
+ /// Relocation offset of the kernel image in virtual memory.
435
+ pub kernel_image_offset : VirtAddr ,
432
436
pub ramdisk_slice_start : Option < VirtAddr > ,
433
437
pub ramdisk_slice_len : u64 ,
434
438
}
@@ -543,6 +547,9 @@ where
543
547
. map ( |addr| addr. as_u64 ( ) )
544
548
. into ( ) ;
545
549
info. ramdisk_len = mappings. ramdisk_slice_len ;
550
+ info. kernel_addr = mappings. kernel_slice_start . as_u64 ( ) ;
551
+ info. kernel_len = mappings. kernel_slice_len as _ ;
552
+ info. kernel_image_offset = mappings. kernel_image_offset . as_u64 ( ) ;
546
553
info. _test_sentinel = boot_config. _test_sentinel ;
547
554
info
548
555
} ) ;
@@ -587,15 +594,21 @@ pub struct PageTables {
587
594
///
588
595
/// Must be the page table that the `kernel` field of this struct refers to.
589
596
///
590
- /// This frame is loaded into the `CR3` register on the final context switch to the kernel.
597
+ /// This frame is loaded into the `CR3` register on the final context switch to the kernel.
591
598
pub kernel_level_4_frame : PhysFrame ,
592
599
}
593
600
594
601
/// Performs the actual context switch.
595
602
unsafe fn context_switch ( addresses : Addresses ) -> ! {
596
603
unsafe {
597
604
asm ! (
598
- "mov cr3, {}; mov rsp, {}; push 0; jmp {}" ,
605
+ r#"
606
+ xor rbp, rbp
607
+ mov cr3, {}
608
+ mov rsp, {}
609
+ push 0
610
+ jmp {}
611
+ "# ,
599
612
in( reg) addresses. page_table. start_address( ) . as_u64( ) ,
600
613
in( reg) addresses. stack_top. as_u64( ) ,
601
614
in( reg) addresses. entry_point. as_u64( ) ,
0 commit comments