Hello , first post
I've been following "The little book of OS development", trying to create a simple OS that says "Hello". It runs on Bochs and VirtualBox but when I write it to a USB stick using dd, and try to boot from it, it does not boot.
It's using the "stage2_eltorito" grub (0.97)
My guess is there is probably some random data somewhere that's not present or set to zero on the emulators. But really I've no idea.
Hope somebody could help!
loader.s:
Code:
global loader
MAGIC_NUMBER equ 0x1BADB002
FLAGS equ 0x0
CHECKSUM equ -MAGIC_NUMBER
KERNEL_STACK_SIZE equ 4096
section .bss
align 4
kernel_stack:
resb KERNEL_STACK_SIZE
section .text
extern kmain
align 4
dd MAGIC_NUMBER
dd FLAGS
dd CHECKSUM
loader:
mov esp, kernel_stack + KERNEL_STACK_SIZE
call kmain
.loop:
jmp .loop
kmain.c:
Code:
unsigned short* framebuf_ptr = (unsigned short*) 0xb8000;
void print(const char* str) {
char* p = (char*) str;
while (*p != '\0') {
*(framebuf_ptr++) = (unsigned short)0x0f00 | (unsigned short)*p++;
}
}
void kmain()
{
print("hello");
}
link.ld:
Code:
ENTRY(loader)
SECTIONS {
. = 0x00100000;
.text ALIGN (0x1000) :
{
*(.text)
}
.rodata ALIGN (0x1000) :
{
*(.rodata*)
}
.data ALIGN (0x1000) :
{
*(.data)
}
.bss ALIGN (0x1000) :
{
*(COMMON)
*(.bss)
}
}
Makefile:
Code:
OBJECTS = loader.o kmain.o
CC = gcc
CFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \
-nostartfiles -nodefaultlibs -O0 -Wall -Wextra -Werror -c
LDFLAGS = -T link.ld -melf_i386
AS = nasm
ASFLAGS = -f elf
all: kernel.elf
kernel.elf: $(OBJECTS)
ld $(LDFLAGS) $(OBJECTS) -o kernel.elf
os.iso: kernel.elf
cp kernel.elf iso/boot/kernel.elf
genisoimage -R \
-b boot/grub/stage2_eltorito \
-no-emul-boot \
-boot-load-size 4 \
-input-charset utf8 \
-quiet \
-boot-info-table \
-o os.iso \
iso
run: os.iso
bochs -f bochsrc.txt -q
%.o: %.c
$(CC) $(CFLAGS) $< -o $@
%.o: %.s
$(AS) $(ASFLAGS) $< -o $@
clean:
rm -rf *.o kernel.elf os.iso
To build & run in bochs:
Code:
make run
dd command I used to write USB:
Code:
sudo dd if=os.iso of=/dev/sdc bs=512b status=progress
Thanks in advance for any help