diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b7c5f31 --- /dev/null +++ b/Makefile @@ -0,0 +1,39 @@ +OBJECTS = loader.o kmain.o + +CC = gcc +CCFLAGS = -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector \ + -nostartfiles -nodefaultlibs -Wall -Wextra -Werror -c +LDFLAGS = -T link.ld -melf_i386 + +AS = nasm +ASFLAGS = -f elf32 + +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 \ + -A os \ + -input-charset utf8 \ + -quiet \ + -boot-info-table \ + -o os.iso \ + iso + +run: os.iso + bochs -f bochsrc.txt -q + +%.o: %.c + $(CC) $(CCFLAGS) $< -o $@ + +%.o: %.s + $(AS) $(ASFLAGS) $< -o $@ + +clean: + rm -rf *.o kernel.elf os.iso bochslog.txt iso/boot/kernel.elf diff --git a/README.md b/README.md index 1de93c0..476f861 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ # lucicOS + +Tools used: + * compiler - gcc + * assembler - nasm + * emulator - bochs + * GRUB legacy bootloader - stage2\_eltorito diff --git a/bochsrc.txt b/bochsrc.txt new file mode 100644 index 0000000..96345f8 --- /dev/null +++ b/bochsrc.txt @@ -0,0 +1,9 @@ +megs: 32 +display_library: sdl +romimage: file=/usr/share/bochs/BIOS-bochs-latest +vgaromimage: file=/usr/share/bochs/VGABIOS-lgpl-latest +ata0-master: type=cdrom, path=os.iso, status=inserted +boot: cdrom +log: bochslog.txt +clock: sync=realtime, time0=local +cpu: count=1, ips=1000000 diff --git a/iso/boot/grub/menu.lst b/iso/boot/grub/menu.lst new file mode 100644 index 0000000..9a5b08c --- /dev/null +++ b/iso/boot/grub/menu.lst @@ -0,0 +1,5 @@ +default=0 +timeout=0 + +title os +kernel /boot/kernel.elf diff --git a/iso/boot/grub/stage2_eltorito b/iso/boot/grub/stage2_eltorito new file mode 100644 index 0000000..9e1617c Binary files /dev/null and b/iso/boot/grub/stage2_eltorito differ diff --git a/kmain.c b/kmain.c new file mode 100644 index 0000000..726596b --- /dev/null +++ b/kmain.c @@ -0,0 +1,3 @@ +void kmain(void) { + +} diff --git a/link.ld b/link.ld new file mode 100644 index 0000000..6984a7e --- /dev/null +++ b/link.ld @@ -0,0 +1,44 @@ +ENTRY(loader) + +SECTIONS { + + /* + * The code should be loaded at an address greater or equal to 1MB because + * lower addresses are reserved to GRUB, BIOS and memory mapped I/O. + * + */ + + . = 0x00100000; + + /* + * Align all sections from all files to a 4KB boundary. + * + */ + + .text ALIGN (0x1000) : { + *(.multiboot) + *(.text) + } + + .rodata ALIGN (0x1000) : { + *(.rodata*) + } + + .data ALIGN (0x1000) : { + *(.data) + } + + /* + * Note: + * COMMON section keeps data objects that are not yet allocated, + * this is just a prelinking section, it will be transformed into bss + * and data after linking. + * + */ + + .bss ALIGN (0x1000) : { + *(COMMON) + *(.bss) + } + +} diff --git a/loader.s b/loader.s new file mode 100644 index 0000000..14c3927 --- /dev/null +++ b/loader.s @@ -0,0 +1,43 @@ +global loader + +; Entry point in the kernel. + +extern kmain + +; GRUB will load the kernel only if it compiles with the multiboot spec. +; The header must contain a magic number, a flag (which can be set to 0x00) +; and the checksum (checksum = - (flag + magic_number)) + +MAGIC_NUMBER equ 0x1BADB002 +FLAGS equ 0x00 +CHECKSUM equ -(MAGIC_NUMBER + FLAGS) + +; Put the header in multiboot section so that it is placed in the first 8Kib +; of the executable. + +section .multiboot + align 4 + + dd MAGIC_NUMBER + dd FLAGS + dd CHECKSUM + +; Create a kstack so that the entry point in the kernel can be called. + +KSTACK_SIZE equ 4096 + +section .bss + align 4 + + kstack resb KSTACK_SIZE + +; Set the stack and call kmain. + +section .text + +loader: + mov esp, kstack + KSTACK_SIZE + call kmain + +.halt: + jmp .halt