0

I just wrote a pretty basic bootloader in assembly, and am now trying to write a kernel. This is what I have so far.

extern "C" void main() {
  int addr = 0xb8000;
  int i = 0x00;
  for (int i = 0x00; i < 0xff; i += 0x11) {
    *(char*)addr = 'A';
    addr++;
    *(char*)addr = i;
    addr++;
  }
  return;
}

All it really does is displays some colors. It does this by writing to video memory, which for QEMU is 0xb8000. If I wanted to flash this "OS" to a USB and boot it up on my laptop, would I need to change the address of video memory? Is there a way to automatically find that address?

John Smith
  • 81
  • 7
  • Why not just give it at try and see what happends – Captain Obvlious Dec 29 '22 at 22:04
  • I think IBM PC-compatible computers always run legacy BIOS bootloaders with VGA in text mode, with the framebuffer at linear address `0xb8000`. If anything is different between your virtual QEMU environment and a real machine, it won't be that. More likely BPB in the bootloader with a USB boot, and make sure segment regs are set properly. [Custom bootloader booted via USB drive produces incorrect output on some computers](https://stackoverflow.com/q/47277702) / [Boot loader doesn't jump to kernel code](https://stackoverflow.com/a/32705076) – Peter Cordes Dec 30 '22 at 02:23
  • Near duplicate: [How can I write directly to the screen?](https://stackoverflow.com/q/4590078) - the first paragraph of Brendan's answer states that the address is fixed, and other parts imply that you'll be in this mode if you haven't changed it yourself after boot. – Peter Cordes Dec 30 '22 at 02:25

1 Answers1

0

Honestly, that should be fine as-is. 0xB8000 is the hardcoded address of the video display in text mode. There's no address space layout randomization going on here, that's the literal address. If you have DOSBOX you could try it out there, it should work as written.

puppydrum64
  • 1,598
  • 2
  • 15