initial commit
This commit is contained in:
18
build.sh
Executable file
18
build.sh
Executable file
@@ -0,0 +1,18 @@
|
||||
x86_64-elf-as -o entry.o entry.s
|
||||
echo "Successfully compiled entry"
|
||||
x86_64-elf-gcc -ffreestanding -c -o kernel.o kernel.c -std=gnu11 -Wall -Wextra
|
||||
echo "Succesfully compiled kernel"
|
||||
x86_64-elf-gcc -ffreestanding -nostdlib -T linker.ld -o os.elf entry.o kernel.o
|
||||
echo "Successfully compiled elf with linker"
|
||||
echo "Connecting to spyro for remote compile..."
|
||||
scp -r iso next@spyro.corp.bbrunson.com:~/OS/
|
||||
echo "Successfully transferred elf to spyro"
|
||||
echo "Compiling ISO with GRUB..."
|
||||
ssh next@spyro.corp.bbrunson.com 'grub-mkrescue -o ~/OS/os.iso ~/OS/iso'
|
||||
echo "Successfully compiled OS"
|
||||
echo "Transferring compiled ISO..."
|
||||
scp -r next@spyro.corp.bbrunson.com:~/OS/os.iso .
|
||||
echo "Successfully tranferred compiled ISO"
|
||||
echo "= Compilation complete ="
|
||||
echo "Booting ISO via QEMU..."
|
||||
qemu-system-x86_64 -cdrom os.iso
|
||||
7
entry.s
Normal file
7
entry.s
Normal file
@@ -0,0 +1,7 @@
|
||||
.section .text
|
||||
.globl _start # Declare _start as global
|
||||
.extern kmain # Declare the external C function
|
||||
|
||||
_start:
|
||||
call kmain # Call the C kernel entry point
|
||||
hlt # Halt if kmain returns
|
||||
BIN
iso/.DS_Store
vendored
Normal file
BIN
iso/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
iso/boot/.DS_Store
vendored
Normal file
BIN
iso/boot/.DS_Store
vendored
Normal file
Binary file not shown.
5
iso/boot/grub/grub.cfg
Normal file
5
iso/boot/grub/grub.cfg
Normal file
@@ -0,0 +1,5 @@
|
||||
set timeout=5
|
||||
menuentry "My OS" {
|
||||
multiboot /boot/os.elf
|
||||
boot
|
||||
}
|
||||
BIN
iso/boot/os.elf
Executable file
BIN
iso/boot/os.elf
Executable file
Binary file not shown.
11
kernel.c
Normal file
11
kernel.c
Normal file
@@ -0,0 +1,11 @@
|
||||
/* kernel.c */
|
||||
#include "multiboot.h"
|
||||
|
||||
// Define the kernel entry point. It must be declared extern "C" if you use C++.
|
||||
void kmain(void) {
|
||||
// Your kernel initialization and code here.
|
||||
// For example, a simple infinite loop.
|
||||
while (1) {
|
||||
// Optionally, add code to print something to the screen.
|
||||
}
|
||||
}
|
||||
24
linker.ld
Normal file
24
linker.ld
Normal file
@@ -0,0 +1,24 @@
|
||||
ENTRY(_start)
|
||||
PHDRS {
|
||||
header PT_LOAD FILEHDR PHDRS ALIGN(4)
|
||||
kernel PT_LOAD FLAGS(5)
|
||||
}
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
/* Place the multiboot header at file offset 0 */
|
||||
. = 0;
|
||||
.multiboot : {
|
||||
KEEP(*(.multiboot))
|
||||
} AT(0) : header
|
||||
|
||||
/* Place the remaining kernel sections starting at 1MB */
|
||||
. = 0x100000;
|
||||
.text : {
|
||||
*(.text*)
|
||||
} : kernel
|
||||
|
||||
.rodata : { *(.rodata*) } : kernel
|
||||
.data : { *(.data*) } : kernel
|
||||
.bss : { *(.bss*) } : kernel
|
||||
}
|
||||
14
make
Normal file
14
make
Normal file
@@ -0,0 +1,14 @@
|
||||
CC=x86_64-elf-gcc
|
||||
CFLAGS=-ffreestanding -O2 -Wall -Wextra
|
||||
LDFLAGS=-T linker.ld
|
||||
|
||||
all: os.bin
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
os.bin: boot.o kernel.o
|
||||
$(CC) $(LDFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
rm -f *.o os.bin
|
||||
17
multiboot.h
Normal file
17
multiboot.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/* multiboot.h */
|
||||
#ifndef MULTIBOOT_H
|
||||
#define MULTIBOOT_H
|
||||
|
||||
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
|
||||
#define MULTIBOOT_HEADER_FLAGS 0x00010003 // Set flags as needed
|
||||
#define MULTIBOOT_HEADER_CHECKSUM -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
|
||||
|
||||
// Place the multiboot header in a dedicated section so that the bootloader can find it.
|
||||
__attribute__((section(".multiboot")))
|
||||
const unsigned int multiboot_header[3] = {
|
||||
MULTIBOOT_HEADER_MAGIC,
|
||||
MULTIBOOT_HEADER_FLAGS,
|
||||
MULTIBOOT_HEADER_CHECKSUM
|
||||
};
|
||||
|
||||
#endif // MULTIBOOT_H
|
||||
Reference in New Issue
Block a user