Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barebones #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ on:
jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build the Docker image
run: docker build buildenv -t bill-buildenv
- name: Docker env
run: docker build . -t bill-buildenv

- name: List files and permissions
run: |
ls -l
chmod +x build.sh

- name: Build
- name: Build iso
run: |
docker run --rm -v "$(pwd):/root/env" bill-buildenv make build-x86_64
docker run --rm -v "$(pwd):/root/env" bill-buildenv /bin/bash -c "./build.sh"

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: "BILL-nightly"
path: "dist/"
name: "BILL-barebones"
path: "."
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM billywonthappen/gcc-cross-x86_64-elf:latest

RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y nasm
RUN apt-get install -y git sudo
RUN apt-get install -y xorriso build-essential

VOLUME /root/env
WORKDIR /root/env
RUN echo "hii"
RUN echo "$PWD"

CMD ["/bin/bash"]
30 changes: 0 additions & 30 deletions Makefile

This file was deleted.

25 changes: 25 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
pwd
cd kernel
pwd

make

cd ..
pwd

git clone https://github.com/limine-bootloader/limine.git --branch=v5.x-branch-binary --depth=1
make -C limine

mkdir -p iso_root
cp -v kernel/bill.elf limine.cfg limine/limine-bios.sys \
limine/limine-bios-cd.bin limine/limine-uefi-cd.bin iso_root/
mkdir -p iso_root/EFI/BOOT
cp -v limine/BOOTX64.EFI iso_root/EFI/BOOT/
cp -v limine/BOOTIA32.EFI iso_root/EFI/BOOT/

xorriso -as mkisofs -b limine-bios-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot limine-uefi-cd.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o image.iso
./limine/limine bios-install image.iso
11 changes: 0 additions & 11 deletions buildenv/Dockerfile

This file was deleted.

87 changes: 87 additions & 0 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <stdint.h>
#include <stddef.h>
#include <limine.h>

static volatile struct limine_framebuffer_request framebuffer_request = {
.id = LIMINE_FRAMEBUFFER_REQUEST,
.revision = 0
};

void *memcpy(void *dest, const void *src, size_t n) {
uint8_t *pdest = (uint8_t *)dest;
const uint8_t *psrc = (const uint8_t *)src;

for (size_t i = 0; i < n; i++) {
pdest[i] = psrc[i];
}

return dest;
}

void *memset(void *s, int c, size_t n) {
uint8_t *p = (uint8_t *)s;

for (size_t i = 0; i < n; i++) {
p[i] = (uint8_t)c;
}

return s;
}

void *memmove(void *dest, const void *src, size_t n) {
uint8_t *pdest = (uint8_t *)dest;
const uint8_t *psrc = (const uint8_t *)src;

if (src > dest) {
for (size_t i = 0; i < n; i++) {
pdest[i] = psrc[i];
}
} else if (src < dest) {
for (size_t i = n; i > 0; i--) {
pdest[i-1] = psrc[i-1];
}
}

return dest;
}

int memcmp(const void *s1, const void *s2, size_t n) {
const uint8_t *p1 = (const uint8_t *)s1;
const uint8_t *p2 = (const uint8_t *)s2;

for (size_t i = 0; i < n; i++) {
if (p1[i] != p2[i]) {
return p1[i] < p2[i] ? -1 : 1;
}
}

return 0;
}

// Halt and catch fire function.
static void hcf(void) {
asm ("cli");
for (;;) {
asm ("hlt");
}
}

void _start(void) {
// Ensure we got a framebuffer.
if (framebuffer_request.response == NULL
|| framebuffer_request.response->framebuffer_count < 1) {
hcf();
}

// Fetch the first framebuffer.
struct limine_framebuffer *framebuffer = framebuffer_request.response->framebuffers[0];

// Note: we assume the framebuffer model is RGB with 32-bit pixels.
for (size_t i = 0; i < 100; i++) {
uint32_t *fb_ptr = framebuffer->address;
fb_ptr[i * (framebuffer->pitch / 4) + i] = 0xffffff;
}

// We're done, just hang...
hcf();
}
46 changes: 46 additions & 0 deletions kernel/linker.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
OUTPUT_FORMAT(elf64-x86-64)

ENTRY(_start)

PHDRS
{
text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */
rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */
data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */
dynamic PT_DYNAMIC FLAGS((1 << 1) | (1 << 2)) ; /* Dynamic PHDR for relocations */
}

SECTIONS
{
. = 0xffffffff80000000;

.text : {
*(.text .text.*)
} :text

. += CONSTANT(MAXPAGESIZE);

.rodata : {
*(.rodata .rodata.*)
} :rodata

. += CONSTANT(MAXPAGESIZE);

.data : {
*(.data .data.*)
} :data

.dynamic : {
*(.dynamic)
} :data :dynamic

.bss : {
*(.bss .bss.*)
*(COMMON)
} :data

/DISCARD/ : {
*(.eh_frame)
*(.note .note.*)
}
}
100 changes: 100 additions & 0 deletions kernel/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
override MAKEFLAGS += -rR
override KERNEL := bill.elf

define DEFAULT_VAR =
ifeq ($(origin $1),default)
override $(1) := $(2)
endif
ifeq ($(origin $1),undefined)
override $(1) := $(2)
endif
endef
override DEFAULT_CC := x86_64-elf-gcc
$(eval $(call DEFAULT_VAR,CC,$(DEFAULT_CC)))

override DEFAULT_LD := x86_64-elf-ld
$(eval $(call DEFAULT_VAR,LD,$(DEFAULT_LD)))

override DEFAULT_CFLAGS := -g -O2 -pipe
$(eval $(call DEFAULT_VAR,CFLAGS,$(DEFAULT_CFLAGS)))

override DEFAULT_CPPFLAGS :=
$(eval $(call DEFAULT_VAR,CPPFLAGS,$(DEFAULT_CPPFLAGS)))

override DEFAULT_NASMFLAGS := -F dwarf -g
$(eval $(call DEFAULT_VAR,NASMFLAGS,$(DEFAULT_NASMFLAGS)))

override DEFAULT_LDFLAGS :=
$(eval $(call DEFAULT_VAR,LDFLAGS,$(DEFAULT_LDFLAGS)))

override CFLAGS += \
-Wall \
-Wextra \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-stack-check \
-fno-lto \
-fPIE \
-m64 \
-march=x86-64 \
-mabi=sysv \
-mno-80387 \
-mno-mmx \
-mno-sse \
-mno-sse2 \
-mno-red-zone

override CPPFLAGS := \
-I. \
$(CPPFLAGS) \
-MMD \
-MP

override LDFLAGS += \
-m elf_x86_64 \
-nostdlib \
-static \
-pie \
--no-dynamic-linker \
-z text \
-z max-page-size=0x1000 \
-T linker.ld

override NASMFLAGS += \
-Wall \
-f elf64

override CFILES := $(shell find -L . -type f -name '*.c')
override ASFILES := $(shell find -L . -type f -name '*.S')
override NASMFILES := $(shell find -L . -type f -name '*.asm')
override OBJ := $(CFILES:.c=.c.o) $(ASFILES:.S=.S.o) $(NASMFILES:.asm=.asm.o)
override HEADER_DEPS := $(CFILES:.c=.c.d) $(ASFILES:.S=.S.d)

.PHONY: all
all: $(KERNEL)

limine.h:
curl -Lo $@ https://github.com/limine-bootloader/limine/raw/trunk/limine.h

$(KERNEL): $(OBJ)
$(LD) $(OBJ) $(LDFLAGS) -o $@

-include $(HEADER_DEPS)

%.c.o: %.c limine.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

%.S.o: %.S limine.h
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

%.asm.o: %.asm
nasm $(NASMFLAGS) $< -o $@

.PHONY: clean
clean:
rm -rf $(KERNEL) $(OBJ) $(HEADER_DEPS)

.PHONY: distclean
distclean: clean
rm -f limine.h
12 changes: 12 additions & 0 deletions limine.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TIMEOUT=5


:BILLOS (KASLR on)
PROTOCOL=limine
KERNEL_PATH=boot:https:///bill.elf

:BILLOS (KASLR off)
PROTOCOL=limine
KASLR=no
KERNEL_PATH=boot:https:///bill.elf

9 changes: 0 additions & 9 deletions src/impl/kernel/main.c

This file was deleted.

9 changes: 0 additions & 9 deletions src/impl/kernel/panic.c

This file was deleted.

Loading