changeset 35:bcb3b68c8147

Added bss end address and load end address to multiboot header
author windel
date Mon, 16 Jan 2012 17:38:00 +0100
parents 8012221dd740
children 91f91ff07ea8
files cos/kernel/goto64.asm cos/kernel/kernel.c cos/kernel/link.ld
diffstat 3 files changed, 18 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/cos/kernel/goto64.asm	Mon Jan 16 13:46:06 2012 +0100
+++ b/cos/kernel/goto64.asm	Mon Jan 16 17:38:00 2012 +0100
@@ -36,11 +36,13 @@
 dd FLAGS
 dd CHECKSUM
 ; item below are present if bit 16 is set in flags
-dd MultiBootHeader ; physical address in file of header (will be 0x100000 if put at start)
-dd 0x100000        ; load_addr: load address, the address to start loading
-dd 0x0             ; load_end_addr: zero indicates to load whole file
-dd 0x0             ; bss_end_addr: zero indicates no bss segment present
-dd loader          ; entry_addr: jump to here
+extern load_end_address ; Import load end address from linker script
+extern bss_end_address  ; Import bss end address to make sure data is zero initialized.
+dd MultiBootHeader  ; physical address in file of header (will be 0x100000 if put at start)
+dd 0x100000         ; load_addr: load address, the address to start loading
+dd load_end_address ; load_end_addr: zero indicates to load whole file
+dd bss_end_address  ; bss_end_addr: zero indicates no bss segment present
+dd loader           ; entry_addr: jump to here
 
 ; 32 bits temporary GDT:
 align 16                                                                        
@@ -95,10 +97,10 @@
 ; Start of loader code:
 loader:
 ; here ebx contains the pointer to the multiboot header, store is for later use.
+; Make sure that multiboot_info is located in the BSS section and that this section
+; is proper zeroed.
 extern multiboot_info
 mov [multiboot_info], ebx
-xor ebx, ebx
-mov [multiboot_info + 4], ebx ; zero the rest of 64 bits address.
 
 ; Check that the CPU supports long mode:
 mov eax, 80000000h
--- a/cos/kernel/kernel.c	Mon Jan 16 13:46:06 2012 +0100
+++ b/cos/kernel/kernel.c	Mon Jan 16 17:38:00 2012 +0100
@@ -14,6 +14,9 @@
    kfree(a);
 }
 
+uint64_t testvar = 1234; // Ends up in data section
+uint64_t testvar2 = 0; // Ends up in bss section
+
 multiboot_info_t *multiboot_info = 0; // Set by startup code.
 
 /* This routine initializes the kernel.
@@ -27,6 +30,10 @@
    keyboard_init();
    timer_init();
 
+   testvar++;
+   testvar2++;
+   printf("Test variable = %d, testvar2 = %d\n", testvar, testvar2);
+
    /* Retrieve memory information from multiboot header */
    uint64_t available_memory = 0;
    if ((multiboot_info->flags & (1<<6)) == (1<<6))
--- a/cos/kernel/link.ld	Mon Jan 16 13:46:06 2012 +0100
+++ b/cos/kernel/link.ld	Mon Jan 16 17:38:00 2012 +0100
@@ -16,10 +16,12 @@
     *(.data)
   }
 
+   load_end_address = .;
   .bss : {
     *(.bss)
    }
 
+   bss_end_address = .;
    kernel_end = .;
 }