Page 1 of 1

Unclear in what mode I work and how to use uint64_t

Posted: Thu Dec 19, 2019 10:40 am
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?

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

Posted: Thu Dec 19, 2019 11:31 am
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.)

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

Posted: Thu Dec 19, 2019 1:56 pm
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...

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

Posted: Thu Dec 19, 2019 5:55 pm
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.