BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / c629653991780509799e2e00d3b074dc0e0ef313

// Related

Nucleus

Barry Initial commit c629653 (3 years, 3 months ago)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..80f3926
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+build/
+*.o
+nucleus
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4f8fdb8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,41 @@
+PRODUCT=nucleus
+
+CC=i686-orion-gcc
+CFLAGS=-Iinclude/
+
+AS=i686-orion-as
+AFLAGS=
+
+LD=i686-orion-gcc
+LFLAGS=-T linker.ld -ffreestanding -nostdlib
+
+AS_SRC := $(shell find . -name '*.S')
+OBJS = $(sort $(subst ./,build/,$(subst .S,.o,$(AS_SRC))))
+
+C_SRC := $(shell find . -name '*.c')
+OBJS += $(sort $(subst ./,build/,$(subst .c,.o,$(C_SRC))))
+
+.PHONY: clean all install
+
+all: $(PRODUCT)
+
+clean:
+	@echo "REMOVING OBJECT FILES"
+	@mkdir -p build
+	@rm -rf build
+	@touch $(PRODUCT)
+	@rm $(PRODUCT)
+
+$(PRODUCT): $(OBJS)
+	@echo "LINKING $@"
+	@$(LD) -o $@ $^ $(LFLAGS)
+
+build/%.o: %.c
+	@echo "COMPILING $<"
+	@mkdir -p $(@D)
+	@$(CC) -c $< -o $@ $(CFLAGS)
+
+build/%.o: %.S
+	@echo "ASSEMBLING $<"
+	@mkdir -p $(@D)
+	@$(AS) -c $< -o $@ $(AFLAGS)
diff --git a/kernel/000.S b/kernel/000.S
new file mode 100644
index 0000000..1ae6600
--- /dev/null
+++ b/kernel/000.S
@@ -0,0 +1,27 @@
+.section .multiboot, "a"
+.global header
+header:
+	.long 0x1BADB002
+	.long 1 | 2
+	.long -(0x1BADB002 + (1 | 2))
+
+	.long 0, 0, 0, 0, 0
+
+.section .bss
+stack_bottom:
+	.skip 16384
+stack_top:
+
+.section .text
+.extern kmain
+.global _start
+_start:
+	mov stack_top, %ebp
+	mov %ebp, %esp
+	push %ebx
+	push %esp
+	call kmain
+	cli
+_end:
+	hlt
+	jmp _end
diff --git a/kernel/main.c b/kernel/main.c
new file mode 100644
index 0000000..c2eb55d
--- /dev/null
+++ b/kernel/main.c
@@ -0,0 +1,21 @@
+/*
+ * This file contains the entrance point for the Kernel proper.  The code here
+ * is called by the bootloader when it finishes.  The kmain routine is
+ * responsible for setting up memory and starting the processes running.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include "multiboot.h"
+
+extern char _bss[], _end[];
+
+/* Kernel main function */
+_Noreturn void
+kmain(uint32_t esp, struct MultibootInfo *mbinfo)
+{
+	void *ebda = (void *) (*((uint16_t *) 0x040E) << 4);
+	memset(_bss, 0, _end - _bss);
+
+	while (1);
+}
diff --git a/kernel/multiboot.h b/kernel/multiboot.h
new file mode 100644
index 0000000..3fde8d0
--- /dev/null
+++ b/kernel/multiboot.h
@@ -0,0 +1,37 @@
+#ifndef MULTIBOOT_H
+#define MULTIBOOT_H
+
+#include <stdint.h>
+
+struct MultibootInfo {
+	uint32_t flags;
+	uint32_t memLower;
+	uint32_t memHigher;
+	uint32_t bootDev;
+	uint32_t cmdline;
+	uint32_t modsCount;
+	uint32_t modsAddr;
+
+	uint32_t symsNum;
+	uint32_t symsSize;
+	uint32_t symsAddr;
+	uint32_t symsShndx;
+
+	uint32_t mmapLen;
+	uint32_t mmapAddr;
+	uint32_t drivesLen;
+	uint32_t drivesAddr;
+
+	uint32_t configTable;
+	uint32_t bootLoader;
+	uint32_t apmTable;
+
+	uint32_t vbeControlInfo;
+	uint32_t vbeModeInfo;
+	uint16_t vbeMode;
+	uint16_t vbeInterfaceSeg;
+	uint16_t vbeInterfaceOff;
+	uint16_t vbeInterfaceLen;
+};
+
+#endif
diff --git a/lib/mem.c b/lib/mem.c
new file mode 100644
index 0000000..a41ec26
--- /dev/null
+++ b/lib/mem.c
@@ -0,0 +1,13 @@
+#include <stddef.h>
+
+/* Fill a region of memory with specified byte */
+void *
+memset(void *dest, int byte, size_t len)
+{
+	unsigned char *a = dest;
+	if (len > 0) {
+		while (len-- > 0)
+			*a++ = byte;
+	}
+	return dest;
+}
diff --git a/linker.ld b/linker.ld
new file mode 100644
index 0000000..0f10da6
--- /dev/null
+++ b/linker.ld
@@ -0,0 +1,34 @@
+ENTRY(_start)
+
+SECTIONS {
+	.text 1M :
+	{
+		KEEP(*(.multiboot))
+		_code = .;
+		*(.text*)
+		. = ALIGN(4096);
+	}
+
+	.data :
+	{
+		_data = .;
+		*(.rodata*)
+		*(.data*)
+		. = ALIGN(4096);
+	}
+
+	.bss :
+	{
+		_bss = .;
+		*(.bss*)
+		*(COMMON)
+		. = ALIGN(4096);
+	}
+
+	_end = .;
+
+	/DISCARD/ :
+	{
+		*(.comment)
+	}
+}