-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,5 @@ modules.order | |
Module.symvers | ||
Mkfile.old | ||
dkms.conf | ||
|
||
*.img |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
.RECIPEPREFIX += | ||
.POSIX: | ||
|
||
BIN = bin | ||
SRC = src | ||
CC = gcc | ||
CFLAGS = -Wextra -fno-builtin -fno-stack-protector -m32 -nostdlib -nostdinc -std=gnu99 -ggdb3 | ||
LINK = ld | ||
LINKFLAGS = -melf_i386 -Tlink.ld | ||
CASM = nasm | ||
ASMFLAGS = -f elf | ||
GRUB = grub-mkrescue | ||
GRUBFLAGS = iso | ||
|
||
BOOT = iso/boot | ||
ELF = $(BIN)/main.elf | ||
IMG = $(BIN)/main.img | ||
|
||
OBJS := $(foreach IN_EXT, .c .asm, $(patsubst %$(IN_EXT), %.o, $(wildcard $(SRC)/*$(IN_EXT)))) $(SRC)/boot.o | ||
|
||
all: $(IMG) | ||
|
||
$(IMG): $(ELF) | ||
@echo " GRUB $<" | ||
@cp '$<' '$(BOOT)' | ||
@$(GRUB) -o '$@' $(GRUBFLAGS) | ||
|
||
$(ELF): $(OBJS) | ||
@echo " LINK $<" | ||
@$(LINK) -o '$(ELF)' $(LINKFLAGS) $^ | ||
|
||
$(SRC)/%.o: $(SRC)/%.c | ||
@mkdir -p $(BIN) | ||
@echo " CC $<" | ||
@$(CC) $(CFLAGS) -o '$@' -c '$<' $(CLIBS) | ||
|
||
$(SRC)/%.o: $(SRC)/%.asm | ||
@echo " CASM $<" | ||
@$(CASM) $(ASMFLAGS) $< -o $@ | ||
|
||
bochs: $(IMG) | ||
CYLINDERS="$$(($$(stat -c '%s' '$<') / 512))" && \ | ||
bochs -qf /dev/null \ | ||
'ata0-master: type=disk, path="$<", mode=flat, cylinders='"$$CYLINDERS"', heads=1, spt=1' \ | ||
'boot: disk' \ | ||
'display_library: sdl' \ | ||
'megs: 128' | ||
|
||
clean: | ||
rm -rf $(BIN) $(SRC)/*.o $(BOOT)/*.elf | ||
|
||
debug: $(IMG) | ||
qemu-system-i386 -hda '$<' -S -s & | ||
@gdb $(ELF) -x gdb.gdb | ||
|
||
qemu: $(IMG) | ||
qemu-system-i386 -drive file=$<,format=raw | ||
|
||
.PHONY: all bochs clean debug qemu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
set timeout=0 | ||
set default="0" | ||
menuentry "main" { | ||
multiboot /boot/main.elf | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
ENTRY(start) | ||
SECTIONS | ||
{ | ||
|
||
.mbheader 0x100000 : | ||
{ | ||
*(.mbheader) | ||
} | ||
.text : | ||
{ | ||
code = .; _code = .; __code = .; | ||
*(.text) | ||
. = ALIGN(4096); | ||
} | ||
|
||
.data : | ||
{ | ||
data = .; _data = .; __data = .; | ||
*(.data) | ||
*(.rodata) | ||
. = ALIGN(4096); | ||
} | ||
|
||
.bss : | ||
{ | ||
bss = .; _bss = .; __bss = .; | ||
*(.bss) | ||
. = ALIGN(4096); | ||
} | ||
|
||
end = .; _end = .; __end = .; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
MBOOT_PAGE_ALIGN equ 1<<0 ; Load kernel and modules on a page boundary | ||
MBOOT_MEM_INFO equ 1<<1 ; Provide your kernel with memory info | ||
MBOOT_HEADER_MAGIC equ 0x1BADB002 ; Multiboot Magic value | ||
; NOTE: We do not use MBOOT_AOUT_KLUDGE. It means that GRUB does not | ||
; pass us a symbol table. | ||
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO | ||
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS) | ||
|
||
|
||
[BITS 32] | ||
|
||
[GLOBAL mboot] | ||
[EXTERN code] | ||
[EXTERN bss] | ||
[EXTERN end] | ||
|
||
section .mbheader | ||
|
||
mboot: | ||
dd MBOOT_HEADER_MAGIC | ||
dd MBOOT_HEADER_FLAGS | ||
dd MBOOT_CHECKSUM | ||
dd mboot | ||
dd code | ||
dd bss | ||
dd end | ||
dd start | ||
|
||
section .text | ||
|
||
[GLOBAL start] | ||
[EXTERN main] | ||
|
||
start: | ||
; Load multiboot information: | ||
push ebx | ||
cli | ||
call main | ||
jmp $ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
struct multiboot; | ||
|
||
int main(struct multiboot *mboot_ptr) { | ||
return 0xDEADBABA; | ||
} |