diff options
author | Ian Moffett <ian@osmora.org> | 2025-09-13 16:49:42 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2025-09-13 16:49:42 -0400 |
commit | ef5fa4b6837e75571d8e76bd218070199d296fce (patch) | |
tree | 879b57314199532404e73e4dcaadd4e5e0fea345 | |
parent | e698061ebaf0cf1a10c11c51a6c6cd46a331959c (diff) |
initial sources
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r-- | src/Makefile | 24 | ||||
-rw-r--r-- | src/arch/i386/conf/e0.ld | 46 | ||||
-rw-r--r-- | src/data/boot/limine.conf | 2 | ||||
-rw-r--r-- | src/sys/Makefile | 17 | ||||
-rw-r--r-- | src/sys/arch/i386/Makefile | 34 | ||||
-rw-r--r-- | src/sys/arch/i386/conf/sys.ld | 35 | ||||
-rw-r--r-- | src/sys/arch/i386/locore.S | 19 | ||||
-rw-r--r-- | src/sys/conf/sys.mk | 15 | ||||
-rw-r--r-- | src/sys/include/sys/cdefs.h | 83 | ||||
-rw-r--r-- | src/sys/include/sys/errno.h | 156 |
10 files changed, 380 insertions, 51 deletions
diff --git a/src/Makefile b/src/Makefile index ea6c7aa..f3232f3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,20 +1,34 @@ TARGET = x86_64 +KBIN = sys/l5 SHIMDIR = shim SHIMBIN = BOOTX64.EFI SYSROOT = root OMAR = tools/omar/bin/omar ISO = lunos.iso +# Build tools +BINUTILS_DIR := $(shell pwd)/cc/toolchain/build-binutils +CC := $(shell pwd)/cc/gcc/bin/x86_64-pc-ethos-gcc +LD := $(BINUTILS_DIR)/bin/x86_64-pc-ethos-ld +AS := $(BINUTILS_DIR)/bin/x86_64-pc-ethos-as + # QEMU emulator flags QEMU_FLAGS = --enable-kvm -serial stdio -cdrom $(ISO) \ -M q35 -cpu host -smp 4 -m 2G .PHONY: all -all: root image +all: root sys image + +.PHONY: sys +sys: + cd sys/; make CC=$(CC) AS=$(AS) LD=$(LD) + cp $(KBIN) root/boot/ root: - mkdir -p root/ - mkdir -p root/boot/ + mkdir -p $(SYSROOT)/ + mkdir -p $(SYSROOT)/boot/ + mkdir -p $(SYSROOT)/usr/include/ + cp -vr sys/include/sys/* $(SYSROOT)/usr/include/ .PHONY: sysroot image: @@ -35,4 +49,6 @@ run: .PHONY: clean clean: - rm -f lunos.iso + rm -rf lunos.iso root + rm -f $(KBIN) + cd sys/; make clean diff --git a/src/arch/i386/conf/e0.ld b/src/arch/i386/conf/e0.ld deleted file mode 100644 index 5b7c7fc..0000000 --- a/src/arch/i386/conf/e0.ld +++ /dev/null @@ -1,46 +0,0 @@ -OUTPUT_FORMAT(elf64-x86-64) -OUTPUT_ARCH(i386:x86-64) -ENTRY(__bsp_entry) - -PHDRS -{ - text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; - rodata PT_LOAD FLAGS((1 << 2)) ; - data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; -} - -SECTIONS -{ - . = 0xFFFFFFFF80000000; - - .text : { - *(.text .text.*) - } :text - - . += CONSTANT(MAXPAGESIZE); - - .rodata : { - *(.rodata .rodata.*) - } :rodata - - . += CONSTANT(MAXPAGESIZE); - - .data : { - *(.data) - } :data - - .bss : { - *(COMMON) - *(.bss .bss.*) - } :data - - . = ALIGN(64); - .data.cacheline_aligned : { - *(.data.cacheline_aligned) - } - - /DISCARD/ : { - *(.eh_frame .eh_frame.*) - *(.note .note.*) - } -} diff --git a/src/data/boot/limine.conf b/src/data/boot/limine.conf index 6d33d8a..ed29e4b 100644 --- a/src/data/boot/limine.conf +++ b/src/data/boot/limine.conf @@ -7,5 +7,5 @@ resolution: 1280x720 /e0 protocol: multiboot2 - kernel_path: boot():/boot/e0 + kernel_path: boot():/boot/l5 module_path: boot():/boot/initrd.omar diff --git a/src/sys/Makefile b/src/sys/Makefile new file mode 100644 index 0000000..52e4e20 --- /dev/null +++ b/src/sys/Makefile @@ -0,0 +1,17 @@ +include conf/sys.mk + +TARGETDIR = arch/$(TARGET) +CC = +LD = +AS = + +.PHONY: all +all: md + +.PHONY: md +md: + cd $(TARGETDIR); make CC=$(CC) LD=$(LD) AS=$(AS) + +.PHONY: clean +clean: + cd $(TARGETDIR); make clean diff --git a/src/sys/arch/i386/Makefile b/src/sys/arch/i386/Makefile new file mode 100644 index 0000000..2db5f9a --- /dev/null +++ b/src/sys/arch/i386/Makefile @@ -0,0 +1,34 @@ +include ../../conf/sys.mk + +.SILENT: +override PROMPT := printf "%s\t\t%s\n" + +TARGET = ../../l5 +TARGET_INC = -I../../target/header/ +CFLAGS = -I../../include/ -I../../include/lib/ $(TARGET_INC) $(MI_CFLAGS) $(MD_CFLAGS) +CFILES = $(shell find . -name "*.c") + +ASMFILES = $(shell find . -name "*.S") +ASMOBJECTS = $(ASMFILES:.S=.S.o) + +DEPS = $(CFILES:.c=.d) +ASMDEPS = $(ASMFILES:.S=.S.d) +OBJECTS = $(CFILES:%.c=%.o) +LD_FLAGS = -Tconf/sys.ld + +.PHONY: all +all: $(OBJECTS) $(ASMOBJECTS) + $(LD) $(OBJECTS) $(ASMOBJECTS) -o $(TARGET) $(LD_FLAGS) + +-include $(DEPS) +%.o: %.c + $(CC) -c $(CFLAGS) $< -o $@ + +-include $(ASMDEPS) +%.S.o: %.S + $(PROMPT) " MD.AS " $< + $(CC) -c $< -o $@ $(CFLAGS) $(MD_CFLAGS) + +.PHONY: clean +clean: + rm -f $(DEPS) $(ASMDEPS) $(OBJECTS) $(ASMOBJECTS) diff --git a/src/sys/arch/i386/conf/sys.ld b/src/sys/arch/i386/conf/sys.ld new file mode 100644 index 0000000..b5d1cf0 --- /dev/null +++ b/src/sys/arch/i386/conf/sys.ld @@ -0,0 +1,35 @@ +ENTRY(_start) + +SECTIONS { + . = 1M; + + .boot : + { + *(.multiboot_header) + } + + . = ALIGN(4K); + .text : + { + *(.text .text.*) + } + + . = ALIGN(4K); + .rodata : + { + *(.rodata .rodata.*) + } + + . = ALIGN(4K); + .data : + { + *(.data .data.*) + } + + . = ALIGN(4K); + .bss : + { + *(.bss .bss.*) + } +} + diff --git a/src/sys/arch/i386/locore.S b/src/sys/arch/i386/locore.S new file mode 100644 index 0000000..5cbdbc2 --- /dev/null +++ b/src/sys/arch/i386/locore.S @@ -0,0 +1,19 @@ + .set MAGIC, 0xe85250d6 + .set ARCH, 0x00 // i386, protected mode + .set LEN, hdr_end - hdr_start + .set CHECKSUM, 0x100000000 - (0xe85250d6 + 0 + (hdr_end - hdr_start)) + + .section .multiboot + .align 4 +hdr_start: + .long MAGIC + .long ARCH + .long LEN + .long CHECKSUM +hdr_end: + + .text + .code32 + .globl _start +_start: + jmp . diff --git a/src/sys/conf/sys.mk b/src/sys/conf/sys.mk new file mode 100644 index 0000000..357303a --- /dev/null +++ b/src/sys/conf/sys.mk @@ -0,0 +1,15 @@ +TARGET = i386 # default +LDSCRIPT = ../md/$(TARGET)/conf/sys.ld # default + +# TODO: Make less rigid +override MD_CFLAGS = -mno-80387 -mno-mmx -mno-3dnow \ + -mno-sse -mno-sse2 -mno-red-zone -mcmodel=kernel + +override MI_CFLAGS = -fexceptions --std=gnu11 -ffreestanding -fno-stack-protector -fno-pic \ + -Werror=implicit -Werror=implicit-function-declaration \ + -Werror=implicit-int -Werror=int-conversion \ + -Werror=missing-prototypes \ + -Werror=incompatible-pointer-types -Werror=int-to-pointer-cast \ + -Werror=return-type -mno-red-zone -mcmodel=kernel \ + -D_KERNEL -Wno-pointer-sign -MMD -nostdinc \ + -Wno-format-pedantic -Wno-attributes $(MD_CFLAGS) diff --git a/src/sys/include/sys/cdefs.h b/src/sys/include/sys/cdefs.h new file mode 100644 index 0000000..91c542e --- /dev/null +++ b/src/sys/include/sys/cdefs.h @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and Ethos0 engineers + * All rights reserved. + * + * 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. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * 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 OWNER 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. + */ + +#ifndef _SYS_CDEFS_H_ +#define _SYS_CDEFS_H_ 1 + +#include <sys/param.h> + +#define __ASMV __asm__ __volatile__ +#if defined(_KERNEL) +#define __isr __attribute__((__interrupt__)) +#endif /* _KERNEL */ +#define __weak __attribute__((__weak__)) +#define __strong __attribute__((__strong__)) +#define __always_inline __attribute__((__always_inline__)) +#define __packed __attribute__((__packed__)) +#define __dead __attribute__((__noreturn__)) +#define __cold __attribute__((__cold__)) +#define __dead_cold __attribute__((__noreturn__, __cold__)) +#define __aligned(n) __attribute__((__aligned__((n)))) +#define __unused __attribute__((__unused__)) +#define __used __attribute__((__used__)) +#define __nothing ((void)0) +#define __likely(exp) __builtin_expect(((exp) != 0), 1) +#define __unlikely(exp) __builtin_expect(((exp) != 0), 0) +#define __static_assert _Static_assert +#define __barrier() __ASMV("" ::: "memory") + +#if defined(__cplusplus) +#define __BEGIN_DECLS extern "C" { +#define __END_DECLS } +#else +#define __BEGIN_DECLS +#define __END_DECLS +#endif + +#ifndef __offsetof +#define __offsetof(st, m) ((size_t)&(((st *)0)->m)) +#endif /* __offsetof */ + +#if defined(_KERNEL) || defined(_E0_SOURCE) +#define offsetof(st, m) __offsetof((st), (m)) +#endif /* _KERNEL || _E0_SOURCE */ + +/* + * Align data on a cache line boundary. This is + * mostly useful for certain locks to ensure they + * have their own cache line to reduce cache line + * bouncing. + */ +#ifndef __cacheline_aligned +#define __cacheline_aligned \ + __attribute__((__aligned__(COHERENCY_UNIT), \ + __section__(".data.cacheline_aligned"))) + +#endif /* __cacheline_aligned */ +#endif /* _KERNEL */ diff --git a/src/sys/include/sys/errno.h b/src/sys/include/sys/errno.h new file mode 100644 index 0000000..84d7c83 --- /dev/null +++ b/src/sys/include/sys/errno.h @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2025 Ian Marco Moffett and Ethos0 engineers + * All rights reserved. + * + * 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. + * 3. Neither the name of the project nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * 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 OWNER 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. + */ + +#ifndef _ERRNO_H_ +#define _ERRNO_H_ + +#define EPERM 1 /* Not super-user */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No children */ +#define EAGAIN 11 /* No more processes */ +#define ENOMEM 12 /* Not enough core */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Mount device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math arg out of domain of func */ +#define ERANGE 34 /* Math result not representable */ +#define ENOMSG 35 /* No message of desired type */ +#define EIDRM 36 /* Identifier removed */ +#define ECHRNG 37 /* Channel number out of range */ +#define EL2NSYNC 38 /* Level 2 not synchronized */ +#define EL3HLT 39 /* Level 3 halted */ +#define EL3RST 40 /* Level 3 reset */ +#define ELNRNG 41 /* Link number out of range */ +#define EUNATCH 42 /* Protocol driver not attached */ +#define ENOCSI 43 /* No CSI structure available */ +#define EL2HLT 44 /* Level 2 halted */ +#define EDEADLK 45 /* Deadlock condition */ +#define ENOLCK 46 /* No record locks available */ +#define EBADE 50 /* Invalid exchange */ +#define EBADR 51 /* Invalid request descriptor */ +#define EXFULL 52 /* Exchange full */ +#define ENOANO 53 /* No anode */ +#define EBADRQC 54 /* Invalid request code */ +#define EBADSLT 55 /* Invalid slot */ +#define EDEADLOCK 56 /* File locking deadlock error */ +#define EBFONT 57 /* Bad font file fmt */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* No data (for no delay io) */ +#define ETIME 62 /* Timer expired */ +#define ENOSR 63 /* Out of streams resources */ +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* The object is remote */ +#define ENOLINK 67 /* The link has been severed */ +#define EADV 68 /* Advertise error */ +#define ESRMNT 69 /* Srmount error */ +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 74 /* Multihop attempted */ +#define ELBIN 75 /* Inode is remote (not really error) */ +#define EDOTDOT 76 /* Cross mount point (not really error) */ +#define EBADMSG 77 /* Trying to read unreadable message */ +#define EFTYPE 79 /* Inappropriate file type or format */ +#define ENOTUNIQ 80 /* Given log. name not unique */ +#define EBADFD 81 /* f.d. invalid for this operation */ +#define EREMCHG 82 /* Remote address changed */ +#define ELIBACC 83 /* Can't access a needed shared lib */ +#define ELIBBAD 84 /* Accessing a corrupted shared lib */ +#define ELIBSCN 85 /* .lib section in a.out corrupted */ +#define ELIBMAX 86 /* Attempting to link in too many libs */ +#define ELIBEXEC 87 /* Attempting to exec a shared library */ +#define ENOSYS 88 /* Function not implemented */ +#define ENMFILE 89 /* No more files */ +#define ENOTEMPTY 90 /* Directory not empty */ +#define ENAMETOOLONG 91 /* File or path name too long */ +#define ELOOP 92 /* Too many symbolic links */ +#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ +#define EPFNOSUPPORT 96 /* Protocol family not supported */ +#define ECONNRESET 104 /* Connection reset by peer */ +#define ENOBUFS 105 /* No buffer space available */ +#define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ +#define EPROTOTYPE 107 /* Protocol wrong type for socket */ +#define ENOTSOCK 108 /* Socket operation on non-socket */ +#define ENOPROTOOPT 109 /* Protocol not available */ +#define ESHUTDOWN 110 /* Can't send after socket shutdown */ +#define ECONNREFUSED 111 /* Connection refused */ +#define EADDRINUSE 112 /* Address already in use */ +#define ECONNABORTED 113 /* Connection aborted */ +#define ENETUNREACH 114 /* Network is unreachable */ +#define ENETDOWN 115 /* Network interface is not configured */ +#define ETIMEDOUT 116 /* Connection timed out */ +#define EHOSTDOWN 117 /* Host is down */ +#define EHOSTUNREACH 118 /* Host is unreachable */ +#define EINPROGRESS 119 /* Connection already in progress */ +#define EALREADY 120 /* Socket already connected */ +#define EDESTADDRREQ 121 /* Destination address required */ +#define EMSGSIZE 122 /* Message too long */ +#define EPROTONOSUPPORT 123 /* Unknown protocol */ +#define ESOCKTNOSUPPORT 124 /* Socket type not supported */ +#define EADDRNOTAVAIL 125 /* Address not available */ +#define ENETRESET 126 +#define EISCONN 127 /* Socket is already connected */ +#define ENOTCONN 128 /* Socket is not connected */ +#define ETOOMANYREFS 129 +#define EPROCLIM 130 +#define EUSERS 131 +#define EDQUOT 132 +#define ESTALE 133 +#define ENOTSUP 134 /* Not supported */ +#define ENOMEDIUM 135 /* No medium (in tape drive) */ +#define ENOSHARE 136 /* No such host or network path */ +#define ECASECLASH 137 /* Filename exists with different case */ +#define EILSEQ 138 +#define EOVERFLOW 139 /* Value too large for defined data type */ + +#endif /* !_ERRNO_H_ */ |