I have followed this tutorial: https://www.youtube.com/watch?v=1rnA6wpF0o4 in order to write a very very basic hello world after boot, as it seems very complete on the next episodes. My problem is that I cannot see what I've done wrong as I verified twice if my code is exactly the same as in the video. It passes grub and then it is just black screen instead of printing the message. I have tried connecting to the forum in the description to ask questions but it is in German and forum page does not load.
So here are the sources: kernel.cpp
void printf(char *str)
{
unsigned short* VideoMemory = (unsigned short*)0xb8000;
for(int i=0; str[i]!= '\0'; ++i)
VideoMemory[i]=(VideoMemory[i] & 0xFF00) | str[i];
}
extern "C" void kernelMain(void* multiboot_structure, unsigned int magicnumber)
{
printf("Hello World!");
while(1);
}
linker.ld
ENTRY(loader)
OUTPUT_FORMAT(elf32-i386)
OUTPUT_ARCH(i386:i386)
SECTIONS
{
. = 0x0100000;
.text :
{
*(.multiboot)
*(.text*)
*(.rodata)
}
.data :
{
start_ctors = .;
KEEP(*( .init_array ));
KEEP(*(SORT_BY_INIT_PRIORITY( .init_array.* )));
end_ctors = .;
*(.data)
}
.bss :
{
*(.bss)
}
/DISCARD/ :
{
*(.fini_array*)
*(.comment)
}
}
loader.s
.set MAGIC, 0x1badb002
.set FLAGS, (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .text
.extern kernelMain
.global loader
loader:
mov $kernel_stack, %esp
push %eax
push %ebx
call kernelMain
_stop:
cli
hlt
jmp _stop
.section .bss
.space 2*1024*1024 # 2 MiB
kernel_stack:
and Makefile
GPPPARAMS = -m32 -fno-use-cxa-atexit -nostdlib -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore
ASPARAMS = --32
LDPARAMS = -melf_i386
objects = loader.o kernel.o
%.o: %.cpp
g++ $(GPPPARAMS) -o $@ -c $<
%.o: %.s
as $(ASPARAMS) -o $@ $<
mykernel.bin: linker.ld $(objects)
ld $(LDPARAMS) -T $< -o $@ $(objects)
install: mykernel.bin
sudo cp $< /boot/mykernel.bin
in /boot/grub/grub.cfg, i added:
menuentry 'My kernel' {
multiboot /boot/mykernel.bin
boot
}
Thanks in advance and have my excuses if I didn't write my question clear enough.
Solution: It only works under MBR/CSM legacy configurations and I found out that all the computers which I tried were UEFI/GPT. Now I do not know how to make it compatible for UEFI/GPT, but if I cannot that's fine, I could not find anything on the internet. It works under Virtualbox, after replacing 0F00 instead of FF00 as it was also writing black on black. (check comments for more details)