Browse Source

pouf! une vache est nee.

master
Mathieu Sérandour 1 year ago
commit
6342611e9e
  1. 4
      .gitignore
  2. 39
      Makefile
  3. BIN
      disk_root/boot/bg.bmp
  4. BIN
      disk_root/boot/kernel.elf
  5. 17
      disk_root/boot/limine.cfg
  6. BIN
      disk_root/boot/limine.sys
  7. 42
      kernel/Makefile
  8. 126
      kernel/entry.c
  9. 0
      kernel/irq.c
  10. 0
      kernel/irq.h
  11. 32
      kernel/linker.ld
  12. BIN
      limine-bootloader/BOOTX64.EFI
  13. 9
      limine-bootloader/LICENSE.md
  14. BIN
      limine-bootloader/limine-cd.bin
  15. BIN
      limine-bootloader/limine-eltorito-efi.bin
  16. BIN
      limine-bootloader/limine-hdd.bin
  17. BIN
      limine-bootloader/limine-install
  18. BIN
      limine-bootloader/limine-install-linux-x86_32
  19. BIN
      limine-bootloader/limine-install-linux-x86_64
  20. BIN
      limine-bootloader/limine-pxe.bin
  21. BIN
      limine-bootloader/limine.sys

4
.gitignore

@ -0,0 +1,4 @@
.vscode
img_moint
*.o
include_cp

39
Makefile

@ -0,0 +1,39 @@
.PHONY: clean all disk kernel force_look
HDD_ROOT := disc_root
HDD_FILE := disk.hdd
USED_LOOPBACK := /dev/loop6
all: disk
disk: kernel
dd if=/dev/zero bs=1M count=0 seek=64 of=$(HDD_FILE)
sudo /sbin/parted -s $(HDD_FILE) mklabel gpt
sudo /sbin/parted -s $(HDD_FILE) mkpart ESP fat32 2048s 100%
sudo /sbin/parted -s $(HDD_FILE) set 1 esp on
./limine-bootloader/limine-install $(HDD_FILE)
sudo losetup -P $(USED_LOOPBACK) $(HDD_FILE)
sudo mkfs.fat -F 32 $(USED_LOOPBACK)p1
mkdir -p img_mount
sudo mount $(USED_LOOPBACK)p1 img_mount
sudo cp -r disk_root/* img_mount/
sync
sudo umount img_mount
sudo /sbin/losetup -d $(USED_LOOPBACK)
kernel: force_look
$(MAKE) -C ./kernel/
clean:
cd ./kernel/ && make clean
rm -f $(HDD_FILE)
force_look:
true

BIN
disk_root/boot/bg.bmp

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

BIN
disk_root/boot/kernel.elf

Binary file not shown.

17
disk_root/boot/limine.cfg

@ -0,0 +1,17 @@
DEFAULT_ENTRY=1
TIMEOUT=10
GRAPHICS=yes
VERBOSE=yes
THEME_MARGIN=64
RESOLUTION=800x600
BACKGROUND_PATH=boot:///boot/bg.bmp
THEME_BACKGROUND=8f000000
BACKGROUND_STYLE=centered
:Stivale2 Test
PROTOCOL=stivale2
RESOLUTION=800x600
KERNEL_PATH=boot:///boot/kernel.elf
BACKGROUND_STYLE=centered

BIN
disk_root/boot/limine.sys

Binary file not shown.

42
kernel/Makefile

@ -0,0 +1,42 @@
KERNEL := ../disk_root/boot/kernel.elf
CC = x86_64-elf-gcc
CFLAGS = -Wall -Wextra -O2 -pipe
INTERNALLDFLAGS := \
-fno-pic -fpie \
-Wl,-static,-pie,--no-dynamic-linker,-ztext \
-static-pie \
-nostdlib \
-Tlinker.ld \
-z max-page-size=0x1000
INTERNALCFLAGS := \
-I/opt/cross/include/ \
-H \
-std=gnu11 \
-ffreestanding \
-fno-stack-protector \
-fno-pic -fpie \
-mno-80387 \
-mno-mmx \
-mno-3dnow \
-mno-sse \
-mno-sse2 \
-mno-red-zone
CFILES := $(shell find ./ -type f -name '*.c')
OBJ := $(CFILES:.c=.o)
.PHONY: all clean
all: $(KERNEL)
$(KERNEL): $(OBJ)
$(CC) $(INTERNALLDFLAGS) $(OBJ) -o $@
%.o: %.c
$(CC) $(CFLAGS) $(INTERNALCFLAGS) -c $< -o $@
clean:
rm -rf $(KERNEL) $(OBJ)

126
kernel/entry.c

@ -0,0 +1,126 @@
#include <stivale2.h>
#include <stddef.h>
#include <stdint.h>
// We need to tell the stivale bootloader where we want our stack to be.
// We are going to allocate our stack as an uninitialised array in .bss.
static uint8_t stack[4096];
// stivale2 uses a linked list of tags for both communicating TO the
// bootloader, or receiving info FROM it. More information about these tags
// is found in the stivale2 specification.
// stivale2 offers a runtime terminal service which can be ditched at any
// time, but it provides an easy way to print out to graphical terminal,
// especially during early boot.
// Read the notes about the requirements for using this feature below this
// code block.
static struct stivale2_header_tag_terminal terminal_hdr_tag = {
// All tags need to begin with an identifier and a pointer to the next tag.
.tag = {
// Identification constant defined in stivale2.h and the specification.
.identifier = STIVALE2_HEADER_TAG_TERMINAL_ID,
// If next is 0, it marks the end of the linked list of header tags.
.next = 0
},
// The terminal header tag possesses a flags field, leave it as 0 for now
// as it is unused.
.flags = 0
};
// We are now going to define a framebuffer header tag, which is mandatory when
// using the stivale2 terminal.
// This tag tells the bootloader that we want a graphical framebuffer instead
// of a CGA-compatible text mode. Omitting this tag will make the bootloader
// default to text mode, if available.
static struct stivale2_header_tag_framebuffer framebuffer_hdr_tag = {
// Same as above.
.tag = {
.identifier = STIVALE2_HEADER_TAG_FRAMEBUFFER_ID,
// Instead of 0, we now point to the previous header tag. The order in
// which header tags are linked does not matter.
.next = (uint64_t)&terminal_hdr_tag
},
// We set all the framebuffer specifics to 0 as we want the bootloader
// to pick the best it can.
.framebuffer_width = 0,
.framebuffer_height = 0,
.framebuffer_bpp = 0
};
// The stivale2 specification says we need to define a "header structure".
// This structure needs to reside in the .stivale2hdr ELF section in order
// for the bootloader to find it. We use this __attribute__ directive to
// tell the compiler to put the following structure in said section.
__attribute__((section(".stivale2hdr"), used))
static struct stivale2_header stivale_hdr = {
// The entry_point member is used to specify an alternative entry
// point that the bootloader should jump to instead of the executable's
// ELF entry point. We do not care about that so we leave it zeroed.
.entry_point = 0,
// Let's tell the bootloader where our stack is.
// We need to add the sizeof(stack) since in x86(_64) the stack grows
// downwards.
.stack = (uintptr_t)stack + sizeof(stack),
// Bit 1, if set, causes the bootloader to return to us pointers in the
// higher half, which we likely want.
.flags = (1 << 1),
// This header structure is the root of the linked list of header tags and
// points to the first one in the linked list.
.tags = (uintptr_t)&framebuffer_hdr_tag
};
// We will now write a helper function which will allow us to scan for tags
// that we want FROM the bootloader (structure tags).
void *stivale2_get_tag(struct stivale2_struct *stivale2_struct, uint64_t id) {
struct stivale2_tag *current_tag = (void *)stivale2_struct->tags;
for (;;) {
// If the tag pointer is NULL (end of linked list), we did not find
// the tag. Return NULL to signal this.
if (current_tag == NULL) {
return NULL;
}
// Check whether the identifier matches. If it does, return a pointer
// to the matching tag.
if (current_tag->identifier == id) {
return current_tag;
}
// Get a pointer to the next tag in the linked list and repeat.
current_tag = (void *)current_tag->next;
}
}
// The following will be our kernel's entry point.
void _start(struct stivale2_struct *stivale2_struct) {
// Let's get the terminal structure tag from the bootloader.
struct stivale2_struct_tag_terminal *term_str_tag;
term_str_tag = stivale2_get_tag(stivale2_struct, STIVALE2_STRUCT_TAG_TERMINAL_ID);
// Check if the tag was actually found.
if (term_str_tag == NULL) {
// It wasn't found, just hang...
for (;;) {
asm ("hlt");
}
}
// Let's get the address of the terminal write function.
void *term_write_ptr = (void *)term_str_tag->term_write;
// Now, let's assign this pointer to a function pointer which
// matches the prototype described in the stivale2 specification for
// the stivale2_term_write function.
void (*term_write)(const char *string, size_t length) = term_write_ptr;
// We should now be able to call the above function pointer to print out
// a simple "Hello World" to screen.
term_write("Bincows beta", 12);
// We're done, just hang...
for (;;) {
asm ("hlt");
}
}

0
kernel/irq.c

0
kernel/irq.h

32
kernel/linker.ld

@ -0,0 +1,32 @@
/* Tell the linker that we want the symbol _start to be our entry point */
ENTRY(_start)
SECTIONS
{
/* We wanna be placed in the higher half, 2MiB above 0 in physical memory. */
. = 0xffffffff80200000;
/* We place the .stivalehdr section containing the header in its own section, */
/* and we use the KEEP directive on it to make sure it doesn't get discarded. */
.stivalehdr : {
KEEP(*(.stivalehdr))
}
/* Then let's place all the other traditional executable sections afterwards. */
.text : {
*(.text*)
}
.rodata : {
*(.rodata*)
}
.data : {
*(.data*)
}
.bss : {
*(COMMON)
*(.bss*)
}
}

BIN
limine-bootloader/BOOTX64.EFI

Binary file not shown.

9
limine-bootloader/LICENSE.md

@ -0,0 +1,9 @@
Copyright 2019, 2020, 2021 mintsuki and contributors.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

BIN
limine-bootloader/limine-cd.bin

Binary file not shown.

BIN
limine-bootloader/limine-eltorito-efi.bin

Binary file not shown.

BIN
limine-bootloader/limine-hdd.bin

Binary file not shown.

BIN
limine-bootloader/limine-install

Binary file not shown.

BIN
limine-bootloader/limine-install-linux-x86_32

Binary file not shown.

BIN
limine-bootloader/limine-install-linux-x86_64

Binary file not shown.

BIN
limine-bootloader/limine-pxe.bin

Binary file not shown.

BIN
limine-bootloader/limine.sys

Binary file not shown.
Loading…
Cancel
Save