Initial Makefile building

This commit is contained in:
Fergal Moran
2020-06-04 21:51:42 +01:00
commit 316553b3af
5 changed files with 56 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.vscode
loader.o

17
Makefile Normal file
View File

@@ -0,0 +1,17 @@
GPPPARAMS = -m32
ASPARAMS = --32
LDPARAMS = -melf_i386
objs = loader.o kernel.o
%.o: %.cpp
g++ $(GPPPARAMS) -o $@ -c $<
%.o: %.s
as $(ASPARAMS) -o $@ $<
ferglos.bin: linker.ld $(objs)
ld $(LDPARAMS) -T linker.ld $< -o $@ $(objs)
install: ferglos.bin
sudo cp $< /boot/ferglos.bin

10
kernel.cpp Normal file
View File

@@ -0,0 +1,10 @@
/*
take in the multiboot structure and the GRUB magic number
not sure I actually need magic_num though
*/
void ferglos_Main(void* mb_struct, unsigned int magic_num) {
printf("Hello, Sailor!");
while (1)
;
}

0
linker.ld Normal file
View File

27
loader.s Normal file
View File

@@ -0,0 +1,27 @@
.set MAGIC, 0x1badb002
.set FLAGS, (1<<0 | 1<<1)
.set CHECKSUM, -(MAGIC + FLAGS) ; #GRUB needs all this stuff, I'll figure out why later
.section multiboot
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .text
.extern ferglos_Main
.global loader
loader:
mov $kernel_stack, %esp
push %eax
push %ebx
call ferglos_Main
_stop:; #infinite loop to ensure kernel stays running
cli
hlt
jmp _stop
.section .bss
.space 2*1024*1024; #2MiB padding to ensure ESP doesn't get landed onto anything useful
kernel_stack: