OSDev.org

The Place to Start for Operating System Developers
It is currently Sun Apr 28, 2024 5:25 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Address of (&) not returning correct address
PostPosted: Mon Jul 24, 2023 12:36 pm 
Offline

Joined: Mon Jul 24, 2023 12:25 pm
Posts: 1
I had basic setup on 32 bit kernel setup, things worked fine there. Now when I try to do same on 64 bit mode, I am facing weird issue.
Basically whenever I am trying to print string, & is not returning correct address. Printing individual chars works fine, or if it pass address as obtained from objdump.

objdump results for ro data
Contents of section .rodata:
10020d 48656c6c 6f0a00 Hello..

printing address of string (using gdb) yield 0x1022b8. This is what gets passed if I call my write_string("Hello"...) function.
if I pass write_string((char*) 10020d, ...) it works fine.

linker configuration:
OUTPUT_FORMAT(elf64-x86-64)
ENTRY(start)
SECTIONS
{
. = 1M;
.text BLOCK(128) : ALIGN(32)
{
*(.multiboot)
*(.text)

}
.rodata : { *(.rodata) }
.data : { *(.data) }
.bss : { *(.bss) }
}

flags:
CFLAGS = -m64 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -Wall -Wextra -Werror -g -c
LDFLAGS = -T link.ld -melf_x86_64
AS = nasm
ASFLAGS = -f elf64

Not sure how I am supposed to debug this. Any pointers will help.


Attachments:
ch2.zip [3.75 KiB]
Downloaded 8 times
Top
 Profile  
 
 Post subject: Re: Address of (&) not returning correct address
PostPosted: Tue Aug 08, 2023 3:24 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
itsankitkp wrote:
Now when I try to do same on 64 bit mode,

But you're not in 64-bit mode. The CPU is in 32-bit mode when GRUB loads your kernel, and you didn't switch the CPU to 64-bit mode, so you're running 64-bit code in 32-bit mode.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group