Unclear in what mode I work and how to use uint64_t

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
User avatar
mrjbom
Member
Member
Posts: 322
Joined: Sun Jul 21, 2019 7:34 am

Unclear in what mode I work and how to use uint64_t

Post by mrjbom »

I'm using GRUB to boot and expect it to boot me into protected mode, but it looks like it's booting me into long mode.

I ran my operating system on a virtual machine with 5120 megabytes of RAM and got this output:

THIS INT32 OUTPUT SECTION
ram_available = 1073282048 bytes
ram_available = 1023 MB
THIS UINT32 OUTPUT SECTION
ram_available = 1073282048 bytes
ram_available = 1023 MB

It is obvious that I get such numbers because of variable overflow, but I expected to see 4 GB because in protected mode it is no longer available. In the end, you can see that all 5 GB are indexed but they are not impossible to remove.
I tried using uint64_t to implement the char* itoaUINT64(uint64_t value, char* result, int base); function, but got a compilation error: Undefined reference to '__divdi3'.

-static-libgcc -lgcc not help.

Source code here
gcc args here in string №73
itoaUINT64() here

How do I solve this problem?
Octocontrabass
Member
Member
Posts: 6280
Joined: Mon Mar 25, 2013 7:01 pm

Re: Unclear in what mode I work and how to use uint64_t

Post by Octocontrabass »

mrjbom wrote:It is obvious that I get such numbers because of variable overflow, but I expected to see 4 GB because in protected mode it is no longer available.
If you use PAE, you can access all memory even in protected mode.
mrjbom wrote:I tried using uint64_t but got a compilation error: Undefined reference to '__divdi3'.
All code compiled with GCC must be linked with libgcc. You can do that by changing line 94 to use GCC instead of LD for linking, and adding "-lgcc" to the command line after your object files. (You may also need to add ./i386-elf-4.9.1-Linux-x86_64/bin/ to your $PATH.)
User avatar
iocoder
Member
Member
Posts: 208
Joined: Sun Oct 18, 2009 5:47 pm
Libera.chat IRC: iocoder
Location: Alexandria, Egypt | Ottawa, Canada
Contact:

Re: Unclear in what mode I work and how to use uint64_t

Post by iocoder »

mrjbom wrote:-static-libgcc -lgcc not help.
Because in your build_all_crosscompile.sh, you added '-lgcc' to your compiler command line, not the linker...
User avatar
mrjbom
Member
Member
Posts: 322
Joined: Sun Jul 21, 2019 7:34 am

Re: Unclear in what mode I work and how to use uint64_t

Post by mrjbom »

Octocontrabass wrote:
mrjbom wrote:It is obvious that I get such numbers because of variable overflow, but I expected to see 4 GB because in protected mode it is no longer available.
If you use PAE, you can access all memory even in protected mode.
mrjbom wrote:I tried using uint64_t but got a compilation error: Undefined reference to '__divdi3'.
All code compiled with GCC must be linked with libgcc. You can do that by changing line 94 to use GCC instead of LD for linking, and adding "-lgcc" to the command line after your object files. (You may also need to add ./i386-elf-4.9.1-Linux-x86_64/bin/ to your $PATH.)
Thanks.
Post Reply