0

I am quite enthusiastic about computers and I managed to create my own bootloader and kernel.

So far it jumps to protected mode from real mode and can execute C code. But the thing is that I cannot write to memory addresses above 0x8000000. The code runs fine but whenever I read from that address it seems that the data was not written.

I know that all memory addresses are not mapped to ram but according to this article addresses from 100000-FEBFFFFF are mapped to ram. So my code should work. http://staff.ustc.edu.cn/~xyfeng/research/cos/resources/machine/mem.htm

Here is a snippet to help you understand

char *data1 = (char*)0x8000000; // This cannot be written to
char *data2 = (char*)0x7ffffff; // This can be written to

*data1 = 'A'; // Will run but not actually write to that ram address
*data2 = 'A'; // Will run properly 

Note - I am running my code in qemu(an emulator) and have not tested this on raw hardware yet.

Any help would be appreciated.

  • The comments in your coding example are in contradiction which each other. –  Feb 16 '22 at 11:04
  • Your platform probably defines 0x8000000 and above as either code segment (aka text segment), or read-only data segment. You might wanna read more about it at https://en.wikipedia.org/wiki/Data_segment#Program_memory. –  Feb 16 '22 at 11:07
  • As a side note, being able to create your own bootloader and kernel just out of being "enthusiastic about computers" (implying that you haven't acquired this profession in the traditional way) is pretty damn impressive! –  Feb 16 '22 at 11:09
  • And both the code and data segment are defined in the gdt as spanning the whole 4gib range, So I don't think its a code segment issue. – Soumish Das Feb 16 '22 at 14:34
  • And I'm 13 i cant get a job yet :D So therefore I consider this my hobby – Soumish Das Feb 16 '22 at 14:34
  • Do you have paging enabled? Is it possible that 0x8000000 is mapped to a different address than the location where you are checking for 'A'? – prl Feb 16 '22 at 20:28
  • Are you sure that the address actually exists in memory? Usually you ask the firmware (BIOS/UEFI) to give you a memory map. The addresses in the range you listed MAY be mapped to RAM, but if there isn't enough RAM there won't be anywhere to write data to. Check [this](https://wiki.osdev.org/Detecting_Memory_(x86)) article. – DarkAtom Feb 17 '22 at 05:35
  • Paging is not enabled as I have not gotten there yet but there might not be available memory since I am using a emulator. Let me check and get back to you – Soumish Das Feb 17 '22 at 06:57
  • 1
    I am very sorry everyone, It seems my emulator just did not have enough memory... Thanks for the help!! – Soumish Das Feb 17 '22 at 07:01
  • @SoumishDas Keep in mind that it is not necessary for the memory range 100000-FEBFFFFF to be fully usable even if you do have enough RAM. Always get the memory map in your bootloader using the BIOS function E820 or the UEFI function GetMemoryMap. While it may work on your emulator, it doesn't mean it will work on any hardware, or other emulators. And if you write to some MMIO accidentally, you could destroy hardware. – DarkAtom Feb 18 '22 at 04:40

0 Answers0