From cf12e449022d83531eab8c0d3746f174f5e9f9ea Mon Sep 17 00:00:00 2001 From: Hjin-Linux Date: Wed, 4 Mar 2026 17:54:26 +0200 Subject: [PATCH] first commit --- LICENSE | 42 ++++++++++++++++++++++++++ Makefile | 23 +++++++++++++++ README.md | 3 ++ bin/.keep | 0 etc/.keep | 0 lib/.keep | 0 linker.ld | 27 +++++++++++++++++ sbin/.keep | 0 share/.keep | 0 sys/arch/x86_64/boot.s | 17 +++++++++++ sys/arch/x86_64/bootloader.asm | 54 ++++++++++++++++++++++++++++++++++ sys/arch/x86_64/kernel.asm | 19 ++++++++++++ sys/kern/main.c | 16 ++++++++++ tools/.keep | 0 usr.sbin/.keep | 0 usr/.keep | 0 16 files changed, 201 insertions(+) create mode 100644 LICENSE create mode 100644 Makefile create mode 100644 README.md create mode 100644 bin/.keep create mode 100644 etc/.keep create mode 100644 lib/.keep create mode 100644 linker.ld create mode 100644 sbin/.keep create mode 100644 share/.keep create mode 100644 sys/arch/x86_64/boot.s create mode 100644 sys/arch/x86_64/bootloader.asm create mode 100644 sys/arch/x86_64/kernel.asm create mode 100644 sys/kern/main.c create mode 100644 tools/.keep create mode 100644 usr.sbin/.keep create mode 100644 usr/.keep diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..6ce21c0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,42 @@ +MAINCLUB OPEN SOFTWARE LICENSE (MCOSL) +Version 1.0 +Copyright (c) 2026 MainClub +All Rights Reserved +1. Purpose +The MainClub Open Software License (MCOSL) ensures that the Licensed Work remains publicly accessible in source code form and may be freely used, studied, modified, and shared on a strictly non-commercial basis. +This License does not qualify as an Open Source license under definitions published by the Open Source Initiative. +2. Definitions +2.1 "Licensed Work" means any software, source code, documentation, or related materials distributed under this License. +2.2 "Derivative Work" means any modification, adaptation, translation, fork, or other work based on the Licensed Work. +2.3 "Distribution" means making the Licensed Work or a Derivative Work available to third parties by any means. +2.4 "Commercial Activity" means any sale, licensing for a fee, paid access, monetized hosting, paid subscription, or other activity intended for commercial advantage or monetary compensation. +3. Grant of Rights +Subject to compliance with this License, each recipient is granted a worldwide, royalty-free, non-exclusive license to: +a) Use the Licensed Work for any purpose; +b) Study and modify the Licensed Work; +c) Create Derivative Works; +d) Distribute the Licensed Work or Derivative Works on a strictly non-commercial basis. +4. Copyleft Requirement +4.1 Any Distribution of the Licensed Work or a Derivative Work must be made under this same License. +4.2 Complete corresponding source code must be provided free of charge. +4.3 No additional legal, contractual, or technical restrictions may be imposed. +4.4 Derivative Works may not be relicensed under any other license. +5. Non-Commercial Restriction +5.1 The Licensed Work and any Derivative Work may not be used for Commercial Activity. +5.2 It is prohibited to: +a) Sell the Licensed Work; +b) Sell a Derivative Work; +c) Charge for access or downloads; +d) Include the Licensed Work in any paid product or service; +e) Provide paid hosting or subscription-based access. +5.3 These restrictions apply equally to all parties, including MainClub. +6. Attribution and Branding +6.1 All copyright notices must be preserved. +6.2 Modifications must be clearly documented. +6.3 The name "MainClub" and related branding may not be used to endorse or promote Derivative Works without prior written permission. +7. No Warranty +THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. +8. Limitation of Liability +IN NO EVENT SHALL ANY COPYRIGHT HOLDER BE LIABLE FOR DAMAGES ARISING FROM THE USE OR DISTRIBUTION OF THE LICENSED WORK. +9. Termination +Any violation of this License automatically terminates the rights granted herein. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0fd4164 --- /dev/null +++ b/Makefile @@ -0,0 +1,23 @@ +CC = x86_64-elf-gcc +LD = x86_64-elf-ld + +CFLAGS = -ffreestanding -O2 -Wall -Wextra +LDFLAGS = -T linker.ld -nostdlib + +OBJS = \ + sys/arch/x86_64/boot.o \ + sys/kern/main.o + +all: kernel.bin + +kernel.bin: $(OBJS) + $(LD) $(LDFLAGS) -o kernel.bin $(OBJS) + +sys/arch/x86_64/boot.o: + $(CC) $(CFLAGS) -c sys/arch/x86_64/boot.s -o sys/arch/x86_64/boot.o + +sys/kern/main.o: + $(CC) $(CFLAGS) -c sys/kern/main.c -o sys/kern/main.o + +clean: + rm -f $(OBJS) kernel.bin diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0a9cbc --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# LiteOS + +Unix like OS created Hjin-BF \ No newline at end of file diff --git a/bin/.keep b/bin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/etc/.keep b/etc/.keep new file mode 100644 index 0000000..e69de29 diff --git a/lib/.keep b/lib/.keep new file mode 100644 index 0000000..e69de29 diff --git a/linker.ld b/linker.ld new file mode 100644 index 0000000..b54c328 --- /dev/null +++ b/linker.ld @@ -0,0 +1,27 @@ +ENTRY(_start) + +SECTIONS +{ + . = 1M; + + .text : + { + *(.multiboot) + *(.text*) + } + + .rodata : + { + *(.rodata*) + } + + .data : + { + *(.data*) + } + + .bss : + { + *(.bss*) + } +} diff --git a/sbin/.keep b/sbin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/share/.keep b/share/.keep new file mode 100644 index 0000000..e69de29 diff --git a/sys/arch/x86_64/boot.s b/sys/arch/x86_64/boot.s new file mode 100644 index 0000000..4cf8b2e --- /dev/null +++ b/sys/arch/x86_64/boot.s @@ -0,0 +1,17 @@ +.section .multiboot +.align 4 +.long 0x1BADB002 +.long 0x0 +.long -(0x1BADB002) + +.section .text +.global _start +.type _start, @function + +_start: + cli + call kernel_main + +.hang: + hlt + jmp .hang diff --git a/sys/arch/x86_64/bootloader.asm b/sys/arch/x86_64/bootloader.asm new file mode 100644 index 0000000..974b6d7 --- /dev/null +++ b/sys/arch/x86_64/bootloader.asm @@ -0,0 +1,54 @@ +[org 0x7C00] +bits 16 + +KERNEL_OFFSET equ 0x1000 + +start: + cli + mov [BOOT_DRIVE], dl + + xor ax, ax + mov ds, ax + mov es, ax + mov ss, ax + mov sp, 0x7C00 + sti + + call load_kernel + + jmp KERNEL_OFFSET + +; ----------------------- +; Зчитування kernel +; ----------------------- + +load_kernel: + mov bx, KERNEL_OFFSET ; куди завантажити + mov dh, 5 ; кількість секторів (тимчасово 5) + + mov dl, [BOOT_DRIVE] + mov ah, 0x02 ; BIOS read sector + mov al, dh ; скільки секторів + mov ch, 0x00 ; cylinder + mov dh, 0x00 ; head + mov cl, 0x02 ; сектор 2 (після bootloader) + int 0x13 + + jc disk_error + ret + +disk_error: + mov si, error_msg +.print: + lodsb + cmp al, 0 + je $ + mov ah, 0x0E + int 0x10 + jmp .print + +BOOT_DRIVE db 0 +error_msg db "Disk read error!", 0 + +times 510 - ($ - $$) db 0 +dw 0xAA55 diff --git a/sys/arch/x86_64/kernel.asm b/sys/arch/x86_64/kernel.asm new file mode 100644 index 0000000..6c94ca4 --- /dev/null +++ b/sys/arch/x86_64/kernel.asm @@ -0,0 +1,19 @@ +[org 0x1000] +bits 16 + +start: + mov si, message + +.print: + lodsb + cmp al, 0 + je .hang + mov ah, 0x0E + int 0x10 + jmp .print + +.hang: + hlt + jmp .hang + +message db "Kernel loaded successfully!", 0 diff --git a/sys/kern/main.c b/sys/kern/main.c new file mode 100644 index 0000000..2f0f747 --- /dev/null +++ b/sys/kern/main.c @@ -0,0 +1,16 @@ +#include + +void kernel_main(void) { + volatile char *video = (volatile char*) 0xB8000; + + const char *msg = "LiteOS kernel started"; + + for (size_t i = 0; msg[i] != '\0'; i++) { + video[i * 2] = msg[i]; + video[i * 2 + 1] = 0x07; // світло-сірий текст + } + + while (1) { + __asm__("hlt"); + } +} diff --git a/tools/.keep b/tools/.keep new file mode 100644 index 0000000..e69de29 diff --git a/usr.sbin/.keep b/usr.sbin/.keep new file mode 100644 index 0000000..e69de29 diff --git a/usr/.keep b/usr/.keep new file mode 100644 index 0000000..e69de29