Initial code

This commit is contained in:
Braiden Vasco 2017-11-01 04:43:42 +00:00
parent 299ac790de
commit cce723d416
5 changed files with 85 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.o
/kernel

20
Makefile Normal file
View File

@ -0,0 +1,20 @@
CCPREFIX = i686-elf-
AS = $(CCPREFIX)as
CC = $(CCPREFIX)gcc
OBJS = boot.s.o main.c.o
all: kernel
clean:
rm kernel $(OBJS)
kernel: $(OBJS)
$(CC) -T linker.ld -o $@ -ffreestanding -nostdlib -O2 -lgcc $(OBJS)
%.c.o: %.c
$(CC) -c $< -o $@ -std=c99 -ffreestanding -O2 -Wall -Wextra
%.s.o: %.s
$(AS) $< -o $@

31
boot.s Normal file
View File

@ -0,0 +1,31 @@
.set ALIGN, 1<<0
.set MEMINFO, 1<<1
.set FLAGS, ALIGN | MEMINFO
.set MAGIC, 0x1BADB002
.set CHECKSUM, -(MAGIC + FLAGS)
.section .multiboot
.align 4
.long MAGIC
.long FLAGS
.long CHECKSUM
.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:
.section .text
.global _start
.type _start, @function
_start:
mov $stack_top, %esp
call main
cli
1:
hlt
jmp 1b
.size _start, . - _start

28
linker.ld Normal file
View File

@ -0,0 +1,28 @@
ENTRY(_start)
SECTIONS
{
. = 1M;
.text BLOCK(4K) : ALIGN(4K)
{
*(.multiboot)
*(.text)
}
.rodata BLOCK(4K) : ALIGN(4K)
{
*(.rodata)
}
.data BLOCK(4K) : ALIGN(4K)
{
*(.data)
}
.bss BLOCK(4K) : ALIGN(4K)
{
*(COMMON)
*(.bss)
}
}

3
main.c Normal file
View File

@ -0,0 +1,3 @@
void main()
{
}