grub memory map of RAM

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
681anki
Posts: 7
Joined: Sun Aug 12, 2012 1:46 am

grub memory map of RAM

Post 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...
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: grub memory map of RAM

Post 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
681anki
Posts: 7
Joined: Sun Aug 12, 2012 1:46 am

Re: grub memory map of RAM

Post 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....
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: grub memory map of RAM

Post 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.
681anki
Posts: 7
Joined: Sun Aug 12, 2012 1:46 am

Re: grub memory map of RAM

Post 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
Last edited by 681anki on Sun Aug 19, 2012 2:20 am, edited 1 time in total.
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: grub memory map of RAM

Post 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.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: grub memory map of RAM

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
zhiayang
Member
Member
Posts: 368
Joined: Tue Dec 27, 2011 7:57 am
Libera.chat IRC: zhiayang

Re: grub memory map of RAM

Post 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.
Post Reply