Hello world!
This commit is contained in:
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
disk.hdd
|
||||||
|
/limine
|
30
Makefile
Normal file
30
Makefile
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
.PHONY: all disk clean
|
||||||
|
|
||||||
|
disk:
|
||||||
|
if [ ! -d limine ]; then \
|
||||||
|
git clone https://github.com/limine-bootloader/limine.git --branch=v9.x-binary --depth=1; \
|
||||||
|
make -C limine; \
|
||||||
|
fi
|
||||||
|
make -C kernel
|
||||||
|
rm -f disk.hdd
|
||||||
|
dd if=/dev/zero bs=1M count=0 seek=64 of=disk.hdd
|
||||||
|
PATH=$$PATH:/usr/sbin:/sbin sgdisk disk.hdd -n 1:2048 -t 1:ef00 -m 1
|
||||||
|
./limine/limine bios-install disk.hdd
|
||||||
|
mformat -i disk.hdd@@1M
|
||||||
|
mmd -i disk.hdd@@1M ::/EFI ::/EFI/BOOT ::/boot ::/boot/limine
|
||||||
|
mcopy -i disk.hdd@@1M kernel/mop2 ::/boot
|
||||||
|
mcopy -i disk.hdd@@1M limine.conf limine/limine-bios.sys ::/boot/limine
|
||||||
|
mcopy -i disk.hdd@@1M limine/BOOTX64.EFI ::/EFI/BOOT
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf limine disk.hdd
|
||||||
|
make -C kernel clean
|
||||||
|
|
||||||
|
all: disk
|
||||||
|
|
||||||
|
run:
|
||||||
|
qemu-system-x86_64 \
|
||||||
|
-d guest_errors \
|
||||||
|
-serial stdio \
|
||||||
|
-hda disk.hdd
|
||||||
|
|
2
kernel/.gitignore
vendored
Normal file
2
kernel/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
*.o
|
||||||
|
mop2
|
58
kernel/Makefile
Normal file
58
kernel/Makefile
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
.PHONY: all clean
|
||||||
|
|
||||||
|
CC := x86_64-elf-gcc
|
||||||
|
LD := x86_64-elf-ld
|
||||||
|
|
||||||
|
override CFLAGS = -Wall \
|
||||||
|
-Wextra \
|
||||||
|
-ffreestanding \
|
||||||
|
-fno-stack-protector \
|
||||||
|
-fno-stack-check \
|
||||||
|
-fno-lto \
|
||||||
|
-fno-PIC \
|
||||||
|
-ffunction-sections \
|
||||||
|
-fdata-sections \
|
||||||
|
-m64 \
|
||||||
|
-march=x86-64 \
|
||||||
|
-mabi=sysv \
|
||||||
|
-mno-80387 \
|
||||||
|
-mno-mmx \
|
||||||
|
-mno-sse \
|
||||||
|
-mno-sse2 \
|
||||||
|
-mno-red-zone \
|
||||||
|
-mcmodel=kernel \
|
||||||
|
-I. \
|
||||||
|
-I../limine
|
||||||
|
|
||||||
|
override LDFLAGS = \
|
||||||
|
-m elf_x86_64 \
|
||||||
|
-nostdlib \
|
||||||
|
-static \
|
||||||
|
-z max-page-size=0x1000 \
|
||||||
|
--gc-sections \
|
||||||
|
-T link.ld
|
||||||
|
|
||||||
|
override NASMFLAGS = \
|
||||||
|
-felf64 \
|
||||||
|
-Wall \
|
||||||
|
-F dwarf -g
|
||||||
|
|
||||||
|
override SRCFILES := $(shell find -L . -type f 2>/dev/null | LC_ALL=C sort)
|
||||||
|
override CFILES := $(filter %.c,$(SRCFILES))
|
||||||
|
override ASFILES := $(filter %.asm,$(SRCFILES))
|
||||||
|
override OBJ := $(patsubst %.c,%.o,$(CFILES)) $(patsubst %.asm,%.o,$(ASFILES))
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
%.o: %.asm
|
||||||
|
nasm $(NASMFLAGS) $< -o $@
|
||||||
|
|
||||||
|
all: mop2
|
||||||
|
|
||||||
|
mop2: $(OBJ)
|
||||||
|
$(LD) $^ $(LDFLAGS) -o $@
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm *.o mop2
|
||||||
|
|
40
kernel/kmain.c
Normal file
40
kernel/kmain.c
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
#include <limine.h>
|
||||||
|
#include <types.h>
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests")))
|
||||||
|
static volatile LIMINE_BASE_REVISION(3);
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests")))
|
||||||
|
static volatile struct limine_framebuffer_request framebuffer_request = {
|
||||||
|
.id = LIMINE_FRAMEBUFFER_REQUEST,
|
||||||
|
.revision = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests_start")))
|
||||||
|
static volatile LIMINE_REQUESTS_START_MARKER;
|
||||||
|
|
||||||
|
__attribute__((used, section(".limine_requests_end")))
|
||||||
|
static volatile LIMINE_REQUESTS_END_MARKER;
|
||||||
|
|
||||||
|
// Halt and catch fire function.
|
||||||
|
static void hcf(void) {
|
||||||
|
for (;;) {
|
||||||
|
asm ("hlt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void kmain(void) {
|
||||||
|
if (LIMINE_BASE_REVISION_SUPPORTED == false) {
|
||||||
|
hcf();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (framebuffer_request.response == NULL
|
||||||
|
|| framebuffer_request.response->framebuffer_count < 1) {
|
||||||
|
hcf();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];
|
||||||
|
|
||||||
|
|
||||||
|
hcf();
|
||||||
|
}
|
68
kernel/link.ld
Normal file
68
kernel/link.ld
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/* Tell the linker that we want an x86_64 ELF64 output file */
|
||||||
|
OUTPUT_FORMAT(elf64-x86-64)
|
||||||
|
|
||||||
|
/* We want the symbol kmain to be our entry point */
|
||||||
|
ENTRY(kmain)
|
||||||
|
|
||||||
|
/* Define the program headers we want so the bootloader gives us the right */
|
||||||
|
/* MMU permissions; this also allows us to exert more control over the linking */
|
||||||
|
/* process. */
|
||||||
|
PHDRS
|
||||||
|
{
|
||||||
|
limine_requests PT_LOAD;
|
||||||
|
text PT_LOAD;
|
||||||
|
rodata PT_LOAD;
|
||||||
|
data PT_LOAD;
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
/* We want to be placed in the topmost 2GiB of the address space, for optimisations */
|
||||||
|
/* and because that is what the Limine spec mandates. */
|
||||||
|
/* Any address in this region will do, but often 0xffffffff80000000 is chosen as */
|
||||||
|
/* that is the beginning of the region. */
|
||||||
|
. = 0xffffffff80000000;
|
||||||
|
|
||||||
|
/* Define a section to contain the Limine requests and assign it to its own PHDR */
|
||||||
|
.limine_requests : {
|
||||||
|
KEEP(*(.limine_requests_start))
|
||||||
|
KEEP(*(.limine_requests))
|
||||||
|
KEEP(*(.limine_requests_end))
|
||||||
|
} :limine_requests
|
||||||
|
|
||||||
|
/* Move to the next memory page for .text */
|
||||||
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
||||||
|
|
||||||
|
.text : {
|
||||||
|
*(.text .text.*)
|
||||||
|
} :text
|
||||||
|
|
||||||
|
/* Move to the next memory page for .rodata */
|
||||||
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
||||||
|
|
||||||
|
.rodata : {
|
||||||
|
*(.rodata .rodata.*)
|
||||||
|
} :rodata
|
||||||
|
|
||||||
|
/* Move to the next memory page for .data */
|
||||||
|
. = ALIGN(CONSTANT(MAXPAGESIZE));
|
||||||
|
|
||||||
|
.data : {
|
||||||
|
*(.data .data.*)
|
||||||
|
} :data
|
||||||
|
|
||||||
|
/* NOTE: .bss needs to be the last thing mapped to :data, otherwise lots of */
|
||||||
|
/* unnecessary zeros will be written to the binary. */
|
||||||
|
/* If you need, for example, .init_array and .fini_array, those should be placed */
|
||||||
|
/* above this. */
|
||||||
|
.bss : {
|
||||||
|
*(.bss .bss.*)
|
||||||
|
*(COMMON)
|
||||||
|
} :data
|
||||||
|
|
||||||
|
/* Discard .note.* and .eh_frame* since they may cause issues on some hosts. */
|
||||||
|
/DISCARD/ : {
|
||||||
|
*(.eh_frame*)
|
||||||
|
*(.note .note.*)
|
||||||
|
}
|
||||||
|
}
|
15
kernel/types.h
Normal file
15
kernel/types.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#ifndef TYPES_H_
|
||||||
|
#define TYPES_H_
|
||||||
|
|
||||||
|
#define NULL ((void *)0)
|
||||||
|
|
||||||
|
typedef char int8;
|
||||||
|
typedef unsigned char uint8;
|
||||||
|
typedef short int16;
|
||||||
|
typedef unsigned short uint16;
|
||||||
|
typedef int int32;
|
||||||
|
typedef unsigned int uint32;
|
||||||
|
typedef long long int64;
|
||||||
|
typedef unsigned long long uint64;
|
||||||
|
|
||||||
|
#endif // TYPES_H_
|
5
limine.conf
Normal file
5
limine.conf
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
timeout: 5
|
||||||
|
|
||||||
|
/mop2
|
||||||
|
protocol: limine
|
||||||
|
path: boot():/boot/mop2
|
Reference in New Issue
Block a user