Page 1 of 1

grub memory map of RAM

Posted: Sun Aug 19, 2012 12:45 am
by 681anki
hi,
I am getting garbage values with grub ...

Code: Select all

if((mbt->flags & (1 << 6)) && (mbt->flags & (1 << 0)) )
		{
		
			
			printf("Lower Memory : %xl",mbt->mem_lower);newline(1);
			
			printf("Upper memory : %xl",mbt->mem_upper);newline(1);
		
			printf("Map Address : %xl",mbt->mmap_addr); newline(1);
			
			printf("Length Map : %xl",mbt->mmap_length);
		
		
		}


I'm getting following values for these....

Lower memory:ffffffff
upper memory:ffffffff
Map Add :ffffffff
length :ffffffff



...So why i'm getting these values ..???

I am BOCHS emulator...

When using "displaymem" i get correct values...??


help me...

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 1:19 am
by zhiayang
681anki wrote:hi,
I am getting garbage values with grub ...

Code: Select all

if((mbt->flags & (1 << 6)) && (mbt->flags & (1 << 0)) )
{
	printf("Lower Memory : %xl",mbt->mem_lower);
        newline(1);
        -snip-
}
I'm getting following values for these....

Lower memory: ffffffff
upper memory: ffffffff
Map Add: ffffffff
length: ffffffff

-snip-
When using "displaymem" i get correct values...??


help me...

I'm going to assume that by 'displaymem' you mean the command at the grub prompt. In this case,
AJ wrote: Hi,

Is the output of printf("%xl", 0) as you would expect?

Cheers,
Adam

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 1:40 am
by 681anki
Hi,

Is the output of printf("%xl", 0) as you would expect?

Cheers,
Adam
yes my printf() works well....

printf("%xl",15);//prints F
printf("%xl"0);//prints 0

Please tell me what is to be done for multiboot.h..to show correct values....

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 1:46 am
by zhiayang
681anki wrote: yes my printf() works well....

printf("%xl",15);//prints F
printf("%xl"0);//prints 0

Please tell me what is to be done for multiboot.h..to show correct values....

If it works in grub but not on your OS, I would say there's something wrong on your end.

1. Did you get multiboot.h from the GNU website?

2. Based on wikipedia, the %xl format string causes printf to expect a 'long' int.

Based on the multiboot specs, mem_lower and mem_upper are supposed to be of type 'unsigned int', not unsigned long.

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 2:11 am
by 681anki
If it works in grub but not on your OS, I would say there's something wrong on your end.

1. Did you get multiboot.h from the GNU website?

2. Based on wikipedia, the %xl format string causes printf to expect a 'long' int.

Based on the multiboot specs, mem_lower and mem_upper are supposed to be of type 'unsigned int', not unsigned long.


i have this code for loader.s

Code: Select all

global loader                           ; making entry point visible to linker
global magic                            ; we will use this in kmain
global mbd                              ; we will use this in kmain
 
extern kmain                            ; kmain is defined in kmain.cpp
 
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ  1<<0                   ; align loaded modules on page boundaries
MEMINFO     equ  1<<1                   ; provide memory map
FLAGS       equ  MODULEALIGN | MEMINFO  ; this is the Multiboot 'flag' field
MAGIC       equ  0x1BADB002             ; 'magic number' lets bootloader find the header
CHECKSUM    equ -(MAGIC + FLAGS)        ; checksum required
 
section .text
 
align 4
    dd MAGIC
    dd FLAGS
    dd CHECKSUM
 
; reserve initial kernel stack space
STACKSIZE equ 0x4000                    ; that's 16k.
 
loader:
    mov  esp, stack + STACKSIZE         ; set up the stack
    mov  [magic], eax                   ; Multiboot magic number
    mov  [mbd], ebx                     ; Multiboot info structure
 
    call kmain                          ; call kernel proper
 
    cli
.hang:
    hlt                                 ; halt machine should kernel return
    jmp  .hang
 
section .bss
 
align 4
stack: resb STACKSIZE                   ; reserve 16k stack on a doubleword boundary
magic: resd 1
mbd:   resd 1

kernel.c

Code: Select all

void kmain(multiboot_info_t *mbd)
{

printf("%x",mbd->mem_lower);// %x will print uint32 in my funcion
}
still same problem

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 2:38 am
by zhiayang
681anki wrote:
If it works in grub but not on your OS, I would say there's something wrong on your end.

1. Did you get multiboot.h from the GNU website?

2. Based on wikipedia, the %xl format string causes printf to expect a 'long' int.

Based on the multiboot specs, mem_lower and mem_upper are supposed to be of type 'unsigned int', not unsigned long.


i have this code for loader.s

Code: Select all

    mov  esp, stack + STACKSIZE         ; set up the stack
    mov  [magic], eax                   ; Multiboot magic number
    mov  [mbd], ebx                     ; Multiboot info structure
 
    call kmain                          ; call kernel proper

kernel.c

Code: Select all

void kmain(multiboot_info_t *mbd)
-snip-
still same problem

I see 2 problems.

1. Arguments to C functions are pushed via the stack; I see you set one up but I don't see a push EAX or push EBX.

2. Arguments are pushed in *reverse* order.

Therefore: When you push the Magic Number, *then* push the structure,
*but* you only take one argument, unexpected things can happen.

Try taking an unsigned int after your multiboot structure argument in kmain.

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 2:45 am
by Combuster
681anki wrote:yes my printf() works well....

printf("%xl",15);//prints F
printf("%xl"0);//prints 0
The correct output if Fl and 0l, so no. Or you must be really bad in posting code since all your examples diplay the same bug.

Re: grub memory map of RAM

Posted: Sun Aug 19, 2012 2:48 am
by zhiayang
Combuster wrote:
681anki wrote:yes my printf() works well....

printf("%xl",15);//prints F
printf("%xl"0);//prints 0
The correct output if Fl and 0l, so no. Or you must be really bad in posting code since all your examples diplay the same bug.
Ha true, it's supposed to be %lx not %xl.