From 8cefd7946fa7a3d0c048b9b8e9187379921fa1d1 Mon Sep 17 00:00:00 2001 From: d0p1 Date: Thu, 29 Jun 2023 06:09:31 +0200 Subject: [PATCH] refactor: rework the entire build system --- .gitignore | 6 +++ Makefile | 58 ++++------------------ bin/Makefile | 3 ++ bin/build.mk | 0 bin/motd/main.pls | 26 +++++++--- docs/build.mk | 5 -- docs/coding-style.txt | 2 + docs/config/Languages.txt | 1 + docs/config/Menu.txt | 24 +++++++-- docs/config/Topics.txt | 15 ++++++ kernel/Makefile | 5 ++ kernel/build.mk | 24 --------- kernel/cpu.inc | 51 +++++++++++++++++++ kernel/debug/msg_en.s | 29 ----------- kernel/drivers/build.mk | 2 - kernel/fs/vfs.inc | 14 ++++++ kernel/head.s | 36 ++++++++------ kernel/i18n/i18n.inc | 10 ++++ kernel/i18n/msg_en.s | 102 ++++++++++++++++++++++++++++++++++++++ kernel/isr.s | 73 ++++++++++++++------------- kernel/kernel.s | 10 ++++ kernel/multiboot.inc | 65 ++++++++++++++++++++++-- kernel/pmm.s | 1 + lib/Makefile | 3 ++ lib/base.inc | 2 + lib/base/Makefile | 4 ++ lib/base/build.mk | 2 - lib/build.mk | 24 --------- lib/crypto/Makefile | 4 ++ lib/pls/std/error.pls | 5 ++ lib/pls/std/io/file.pls | 3 ++ share/mk/stupid.clean.mk | 5 ++ share/mk/stupid.kernel.mk | 38 ++++++++++++++ share/mk/stupid.lib.mk | 33 ++++++++++++ share/mk/stupid.own.mk | 32 ++++++++++++ share/mk/stupid.prog.mk | 41 +++++++++++++++ share/mk/stupid.subdir.mk | 20 ++++++++ share/mk/stupid.sys.mk | 19 +++++++ thirdparty/Makefile | 3 ++ tools/build.mk | 9 ---- tools/create-iso | 7 +++ 41 files changed, 607 insertions(+), 209 deletions(-) create mode 100644 bin/Makefile delete mode 100644 bin/build.mk delete mode 100644 docs/build.mk create mode 100644 docs/coding-style.txt create mode 100644 kernel/Makefile delete mode 100644 kernel/build.mk create mode 100644 kernel/cpu.inc delete mode 100644 kernel/debug/msg_en.s delete mode 100644 kernel/drivers/build.mk create mode 100644 kernel/fs/vfs.inc create mode 100644 kernel/i18n/i18n.inc create mode 100644 kernel/i18n/msg_en.s create mode 100644 lib/Makefile create mode 100644 lib/base/Makefile delete mode 100644 lib/base/build.mk delete mode 100644 lib/build.mk create mode 100644 lib/crypto/Makefile create mode 100644 lib/pls/std/error.pls create mode 100644 lib/pls/std/io/file.pls create mode 100644 share/mk/stupid.clean.mk create mode 100644 share/mk/stupid.kernel.mk create mode 100644 share/mk/stupid.lib.mk create mode 100644 share/mk/stupid.own.mk create mode 100644 share/mk/stupid.prog.mk create mode 100644 share/mk/stupid.subdir.mk create mode 100644 share/mk/stupid.sys.mk create mode 100644 thirdparty/Makefile delete mode 100644 tools/build.mk diff --git a/.gitignore b/.gitignore index fa7e052..e6578db 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ *.a *.dump vmstupid +vmstupid-dbg /sysroot @@ -17,3 +18,8 @@ log.txt /docs/html /docs/config/Data + +a.out +*.old +/bx_enh_dbg.ini +bochsrc.bxrc diff --git a/Makefile b/Makefile index fbb1715..275cce5 100644 --- a/Makefile +++ b/Makefile @@ -1,53 +1,13 @@ -.SUFFIXES: -.DELETE_ON_ERROR: .DEFAULT_GOAL := all +TOPDIR := $(CURDIR) +export TOPDIR -AS = nasm -LD = ld.lld -OBJDUMP = llvm-objdump -QEMU = qemu-system-i386 -RM = rm -f -MKCWD = mkdir -p $(@D) -INSTALL = install +SUBDIR := thirdparty lib bin kernel -BIN_DIR = bin -DOC_DIR = docs -KERNEL_DIR = kernel -LIB_DIR = lib -TOOLS_DIR = tools +.PHONY: docs +docs: + -mkdir -p docs/html + naturaldocs -p docs/config -img docs/img -xi tmp -i . -o HTML docs/html + cp docs/img/favicon.ico docs/html/ -include $(TOOLS_DIR)/build.mk - -ASFLAGS = -F dwarf -g -DSTUPID_VERSION="\"$(shell $(GIT-VERSION))\"" -Ilib \ - -DBUILD_DATE="\"$(shell date --iso)\"" \ - -DNASM_VERSION="\"$(shell nasm -v)\"" -QEMUFLAGS = -serial stdio -no-reboot - -GARBADGE = stupid.iso - -include $(KERNEL_DIR)/build.mk -include $(LIB_DIR)/build.mk -include $(BIN_DIR)/build.mk -include $(DOC_DIR)/build.mk - -all: stupid.iso - -sysroot: $(KERNEL_BIN) $(KERNEL_DUMP) $(LIBS_BIN) - $(INSTALL) -d $@ - $(INSTALL) -d $@/bin - $(INSTALL) -d $@/lib - $(INSTALL) $(KERNEL_BIN) $@ - $(INSTALL) $(LIBS_BIN) $@/lib - -stupid.iso: sysroot - $(CREATE-ISO) $@ $< - -run: stupid.iso - $(QEMU) $(QEMUFLAGS) -cdrom $< - -clean: - $(RM) $(GARBADGE) - -re: clean all - -.PHONY: all clean re +include $(TOPDIR)/share/mk/stupid.subdir.mk diff --git a/bin/Makefile b/bin/Makefile new file mode 100644 index 0000000..44f981f --- /dev/null +++ b/bin/Makefile @@ -0,0 +1,3 @@ +NOSUBDIR := 1 + +include $(TOPDIR)/share/mk/stupid.subdir.mk diff --git a/bin/build.mk b/bin/build.mk deleted file mode 100644 index e69de29..0000000 diff --git a/bin/motd/main.pls b/bin/motd/main.pls index 07c5b58..3633c3e 100644 --- a/bin/motd/main.pls +++ b/bin/motd/main.pls @@ -3,14 +3,26 @@ */ /* - * Procedure: Motd - * Program entry point + * Procedure: main + * + * Program entry point. */ -Motd: PROC OPTIONS(MAIN); - DCL in FILE; - OPEN FILE(in) TITLE('/etc/motd') INPUT; - DO ; + +PROC main; + DCL in AS File; + DCL line AS String; + DCL now AS DateTime; + + now = [[DateTime allocate] now]; + IF now == NIL THEN exit(1); + in = [[File allocate] initOpen:"/etc/motd"]; + IF in == NIL THEN exit(1); + + WHILE [in readLine:line] != EOF; + print(line); END; - CLOSE FILE(in); + + [in release]; + [now release]; END; diff --git a/docs/build.mk b/docs/build.mk deleted file mode 100644 index 0e652fc..0000000 --- a/docs/build.mk +++ /dev/null @@ -1,5 +0,0 @@ -.PHONY: docs -docs: - -mkdir -p $(DOC_DIR)/html - naturaldocs -p $(DOC_DIR)/config -img $(DOC_DIR)/img -xi tmp -i . -o HTML $(DOC_DIR)/html - cp $(DOC_DIR)/img/favicon.ico $(DOC_DIR)/html/ diff --git a/docs/coding-style.txt b/docs/coding-style.txt new file mode 100644 index 0000000..bd767a6 --- /dev/null +++ b/docs/coding-style.txt @@ -0,0 +1,2 @@ +File: Coding Style + diff --git a/docs/config/Languages.txt b/docs/config/Languages.txt index eb4644d..2581e6e 100644 --- a/docs/config/Languages.txt +++ b/docs/config/Languages.txt @@ -116,6 +116,7 @@ Format: 1.51 Alter Language: Assembly Add Extensions: s inc + Struct Prototype Ender: endstruc Language: PL/S diff --git a/docs/config/Menu.txt b/docs/config/Menu.txt index b66a439..30d26b8 100644 --- a/docs/config/Menu.txt +++ b/docs/config/Menu.txt @@ -40,6 +40,7 @@ Timestamp: Updated yyyy/mm/dd File: Introduction (docs/intro.txt) Link: Source Code (https://github.com/d0p1s4m4/StupidOS) +File: Coding Style (docs/coding-style.txt) File: FAQ (docs/faq.txt) Group: Kernel { @@ -56,11 +57,9 @@ Group: Kernel { File: serial.s (no auto-title, kernel/drivers/serial.s) } # Group: Driver - Group: Debug { - - File: msg_en (kernel/debug/msg_en.s) - } # Group: Debug - + File: kernel.s (kernel/kernel.s) + File: msg_en (kernel/i18n/msg_en.s) + File: pmm.s (kernel/pmm.s) } # Group: Kernel Group: Lib { @@ -107,6 +106,21 @@ Group: Bin { } # Group: Bin +Group: Share { + + Group: Mk { + + File: stupid.clean.mk (share/mk/stupid.clean.mk) + File: stupid.kernel.mk (share/mk/stupid.kernel.mk) + File: stupid.lib.mk (share/mk/stupid.lib.mk) + File: stupid.own.mk (share/mk/stupid.own.mk) + File: stupid.prog.mk (share/mk/stupid.prog.mk) + File: stupid.subdir.mk (share/mk/stupid.subdir.mk) + File: stupid.sys.mk (share/mk/stupid.sys.mk) + } # Group: Mk + + } # Group: Share + Group: Index { Index: Everything diff --git a/docs/config/Topics.txt b/docs/config/Topics.txt index 2153090..2703bcc 100644 --- a/docs/config/Topics.txt +++ b/docs/config/Topics.txt @@ -79,3 +79,18 @@ Format: 1.51 # If you add something that you think would be useful to other developers # and should be included in Natural Docs by default, please e-mail it to # topics [at] naturaldocs [dot] org. + + +Alter Topic Type: Macro + + Add Keywords: + equ + + +Topic Type: Struct + + Plural: Structs + Class Hierarchy: Yes + + Keywords: + struc diff --git a/kernel/Makefile b/kernel/Makefile new file mode 100644 index 0000000..05123f8 --- /dev/null +++ b/kernel/Makefile @@ -0,0 +1,5 @@ +KERNEL = vmstupid +SRCS = head.s gdt.s pic.s isr.s idt.s pmm.s paging.s \ + lib/log.s drivers/serial.s + +include $(TOPDIR)/share/mk/stupid.kernel.mk diff --git a/kernel/build.mk b/kernel/build.mk deleted file mode 100644 index 4760e5a..0000000 --- a/kernel/build.mk +++ /dev/null @@ -1,24 +0,0 @@ -include kernel/drivers/build.mk - -KERNEL_SRCS = head.s gdt.s pic.s isr.s idt.s pmm.s paging.s lib/log.s -KERNEL_OBJS = $(addprefix kernel/, $(KERNEL_SRCS:.s=.o) $(DRIVERS_OBJS)) -KERNEL_BIN = vmstupid -KERNEL_DUMP = $(KERNEL_BIN).dump - -KERNEL_ASFLAGS = $(ASFLAGS) -D__KERNEL__ -Ikernel - -GARBADGE += $(KERNEL_OBJS) $(KERNEL_BIN) $(KERNEL_DUMP) - -$(KERNEL_BIN): $(KERNEL_OBJS) - $(LD) -T $(KERNEL_DIR)/linker.ld -nostdlib -o $@ $^ - -$(KERNEL_DUMP): $(KERNEL_BIN) - $(OBJDUMP) -D $^ > $@ - -kernel/lib/%.o: lib/base/%.s - @$(MKCWD) - $(AS) -felf -o $@ $< $(KERNEL_ASFLAGS) - -kernel/%.o: kernel/%.s - $(AS) -felf -o $@ $< $(KERNEL_ASFLAGS) - diff --git a/kernel/cpu.inc b/kernel/cpu.inc new file mode 100644 index 0000000..97b83ed --- /dev/null +++ b/kernel/cpu.inc @@ -0,0 +1,51 @@ +struc tss + .link: resd 1 + +endstruc + +struc gdt_entry + .limit_low: resw 1 + .base_low: resw 1 + .base_mid: resb 1 + .access: resb 1 + .flags: resb 1 + .base_high: resb 1 +endstruc + +struc idt_entry + .limit_low: resw 1 + .selector: resw 1 + .zero: resb 1 + .attr: resb 1 + .base_high: resw 1 +endstruc + +struc intframe + ;; registers + .edi: resd 1 + .esi: resd 1 + .ebp: resd 1 + .esp: resd 1 + .ebx: resd 1 + .edx: resd 1 + .ecx: resd 1 + .eax: resd 1 + + ;; + .gs: resd 1 + .fs: resd 1 + .es: resd 1 + .ds: resd 1 + .intno: resd 1 + + ;; by x86 hardware + .err: resd 1 + .eip: resd 1 + .cs: resd 1 + .eflags: resd 1 + + ;; crossring + .useresp: resd 1 + .ss: resd 1 +endstruc + diff --git a/kernel/debug/msg_en.s b/kernel/debug/msg_en.s deleted file mode 100644 index df1025d..0000000 --- a/kernel/debug/msg_en.s +++ /dev/null @@ -1,29 +0,0 @@ -; file: msg_en -; English strings - -.section rodata -msg_hello_world: - db "StupidOS v", STUPID_VERSION, " (built with ", NASM_VERSION, " on ", BUILD_DATE, ")", 0 -msg_boot_info: - db "Bootloader: %s", 0 -msg_pmm_initialized: - db "PMM initialized", 0 -err_invalid_boot_magic: - db "[ERROR] Invalid boot magic (got: %x, expected: 0x2BADB002)", 0 -err_cannot_map_memory: - db "[ERROR] Can't map memory", 0 -warn_no_mmap: - db "[WARN] mmap flag not set", 0 -msg_mmap_entry: - db "Memory Map Entry:", 0xA - db 0x9, "Address: (hi): %x (lo): %x", 0xA - db 0x9, "Length: (hi): %x (lo): %x", 0xA - db 0x9, "Type: %x", 0 -msg_mem_block: - db "Free Memory:", 0xA - db 0x9, "Address: %x", 0xA - db 0x9, "Length: %x", 0 -msg_max_mem: - db "Max memory: %x", 0 -msg_bitmap_stored_at: - db "Bitmap stored at: %x", 0 diff --git a/kernel/drivers/build.mk b/kernel/drivers/build.mk deleted file mode 100644 index 4eb0dbc..0000000 --- a/kernel/drivers/build.mk +++ /dev/null @@ -1,2 +0,0 @@ -DRIVERS_SRCS = serial.s -DRIVERS_OBJS = $(addprefix drivers/, $(DRIVERS_SRCS:.s=.o)) diff --git a/kernel/fs/vfs.inc b/kernel/fs/vfs.inc new file mode 100644 index 0000000..f78618e --- /dev/null +++ b/kernel/fs/vfs.inc @@ -0,0 +1,14 @@ + +struc superblock + .devid: resd 1 + .size: resd 1 + .ninode: resd 1 + .fs_type: resd 1 +endstruc + +struc inode + .devid: resd 1 + .size: resd 1 + .inode: resd 1s + .access: resd 1 +endstruc diff --git a/kernel/head.s b/kernel/head.s index 63d7f12..101cbb5 100644 --- a/kernel/head.s +++ b/kernel/head.s @@ -5,16 +5,22 @@ %include "base.inc" %include "multiboot.inc" -MULTIBOOT_MAGIC equ 0x1BADB002 -MULTIBOOT_ALIGN equ 1 << 0 -MULTIBOOT_MEMINFO equ 1 << 1 -MULTIBOOT_FLAGS equ MULTIBOOT_ALIGN | MULTIBOOT_MEMINFO +; Define: MB_HDR_FLAGS +MB_HDR_FLAGS equ MB_HDR_ALIGN | MB_HDR_MEMINFO | MB_HDR_VIDEO section .multiboot align 4 - dd MULTIBOOT_MAGIC - dd MULTIBOOT_FLAGS - dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) + istruc mb_header + at mb_header.magic, dd MB_HDR_MAGIC + at mb_header.flags, dd MB_HDR_FLAGS + at mb_header.checksum, dd -(MB_HDR_MAGIC + MB_HDR_FLAGS) + + ; video mode info + at mb_header.mode_type, dd 0 + at mb_header.width, dd 1024 + at mb_header.height, dd 768 + at mb_header.depth, dd 32 + iend section .bss align 16 @@ -25,7 +31,8 @@ stack_top: section .text ; Function: entry - ; + ; setup cpu and paging before calling + ; ; in: ; EAX - Multiboot magic ; EBX - Multiboot structure @@ -36,18 +43,17 @@ section .text global entry entry: mov esp, stack_top - cli + cli ; disable interrupt - mov edi, eax - mov esi, ebx + mov edi, eax ; save multiboot magic in EDI + mov esi, ebx ; save multiboot structure in ESI ;; initialize serial (mostly used for debug) extern serial_init call serial_init - ;; eax <- magic - ;; ebx <- multiboot struct - cmp edi, 0x2BADB002 + ;; make sure we use a multiboot compliant bootloader + cmp edi, MB_MAGIC je .multiboot_valid LOG err_invalid_boot_magic, edi @@ -95,7 +101,7 @@ hang: section .rodata -msg_hello_world db "StupidOS v", STUPID_VERSION, " (built with ", NASM_VERSION, " on ", BUILD_DATE, ")", 0 +msg_hello_world db "StupidOS v", STUPID_VERSION, " (built with ", __NASM_VER__, " on ", __DATE__, " ", __TIME__, ")", 0 msg_boot_info db "Bootloader: %s", 0 msg_pmm_initialized db "PMM initialized", 0 err_invalid_boot_magic db "[ERROR] Invalid boot magic (got: %x, expected: 0x2BADB002)", 0 diff --git a/kernel/i18n/i18n.inc b/kernel/i18n/i18n.inc new file mode 100644 index 0000000..ba59ee3 --- /dev/null +++ b/kernel/i18n/i18n.inc @@ -0,0 +1,10 @@ +struc lang_entry + .code: resb 2 + .data: resd 1 + .next: resd 1 +endstruc + +struc msg_table + .hello_world: resd 1 + .cpu_exceptions: resd 32 +endstruc diff --git a/kernel/i18n/msg_en.s b/kernel/i18n/msg_en.s new file mode 100644 index 0000000..0df1222 --- /dev/null +++ b/kernel/i18n/msg_en.s @@ -0,0 +1,102 @@ +; file: msg_en +; English strings + +%include "i18n.inc" + +.section rodata +global lang_en +lang_en: + istruc lang_entry + at lang_entry.code: db "en" + at lang_entry.data: dd msg_en + at lang_entry.next: dd 0 + iend + +msg_en: + istruc msg_table + at msg_table.hello_world: dd msg_hello_world + + at msg_table.cpu_exceptions: + dd msg_int_division_zero + dd msg_int_debug + dd msg_int_nmi + dd msg_int_breakpoint + dd msg_int_overflow + dd msg_int_range_exceeded + dd msg_int_invalid_opcode + dd msg_int_device_not_available + dd msg_int_double_fault + dd msg_int_coproc_segment_overrun + dd msg_int_invalid_tss + dd msg_int_seg_not_present + dd msg_int_stack_segfault + dd msg_int_gpf + dd msg_int_page_fault + dd msg_int_reserved + dd msg_int_fp_exception + dd msg_int_align_check + dd msg_int_machine_check + dd msg_int_simd_exception + dd msg_int_virt_exception + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + dd msg_int_reserved + iend + +msg_hello_world: + db "StupidOS v", STUPID_VERSION, " (built with ", NASM_VERSION, " on ", BUILD_DATE, ")", 0 +msg_boot_info: + db "Bootloader: %s", 0 +msg_pmm_initialized: + db "PMM initialized", 0 +err_invalid_boot_magic: + db "[ERROR] Invalid boot magic (got: %x, expected: 0x2BADB002)", 0 +err_cannot_map_memory: + db "[ERROR] Can't map memory", 0 +warn_no_mmap: + db "[WARN] mmap flag not set", 0 +msg_mmap_entry: + db "Memory Map Entry:", 0xA + db 0x9, "Address: (hi): %x (lo): %x", 0xA + db 0x9, "Length: (hi): %x (lo): %x", 0xA + db 0x9, "Type: %x", 0 +msg_mem_block: + db "Free Memory:", 0xA + db 0x9, "Address: %x", 0xA + db 0x9, "Length: %x", 0 +msg_max_mem: + db "Max memory: %x", 0 +msg_bitmap_stored_at: + db "Bitmap stored at: %x", 0 + + +msg_int_division_zero: db "Division by zero", 0x0 +msg_int_debug: db "Debug", 0x0 +msg_int_nmi: db "Non-maskable interrupt", 0x0 +msg_int_breakpoint: db "Breakpoint", 0x0 +msg_int_overflow: db "Overflow", 0x0 +msg_int_range_exceeded: db "Bound range exceeded", 0x0 +msg_int_invalid_opcode: db "Invalid Opcode", 0x0 +msg_int_device_not_available: db "Device not available", 0x0 +msg_int_double_fault: db "Double fault", 0x0 +msg_int_coproc_segment_overrun: db "Coprocessor segment overrun", 0x0 +msg_int_invalid_tss: db "Invalid TSS", 0x0 +msg_int_seg_not_present: db "Segment not present", 0x0 +msg_int_stack_segfault: db "Stack segment fault", 0x0 +msg_int_gpf: db "General Protection Fault", 0x0 +msg_int_page_fault: db "Page fault", 0x0 +msg_int_reserved: db "Reserved", 0x0 +msg_int_fp_exception: db "x87 Floating-Point Exception", 0x0 +msg_int_align_check: db "Aligment check", 0x0 +msg_int_machine_check: db "Machine check", 0x0 +msg_int_simd_exception: db "SIMD Floating-Point exception", 0x0 +msg_int_virt_exception: db "Virtualization exception", 0x0 +msg_int_sec_exception: db "Security exception", 0x0 diff --git a/kernel/isr.s b/kernel/isr.s index 11200c4..a8f61ec 100644 --- a/kernel/isr.s +++ b/kernel/isr.s @@ -1,5 +1,6 @@ [BITS 32] +%include "cpu.inc" %include "base.inc" %macro ISR_NO_ERR 1 @@ -8,7 +9,7 @@ isr%1: xchg bx, bx push dword 0 push dword %1 - jmp isr_handler + jmp isr_common %endmacro %macro ISR_ERR 1 @@ -16,37 +17,8 @@ global isr%1 isr%1: xchg bx, bx push dword %1 - jmp isr_handler -%endmacro - -struc intframe - ;; registers - .edi: resd 1 - .esi: resd 1 - .ebp: resd 1 - .esp: resd 1 - .ebx: resd 1 - .edx: resd 1 - .ecx: resd 1 - .eax: resd 1 - - ;; - .gs: resd 1 - .fs: resd 1 - .es: resd 1 - .ds: resd 1 - .intno: resd 1 - - ;; by x86 hardware - .err: resd 1 - .eip: resd 1 - .cs: resd 1 - .eflags: resd 1 - - ;; crossring - .useresp: resd 1 - .ss: resd 1 -endstruc + jmp isr_common +%endmacro section .text @@ -89,8 +61,16 @@ panic: ;jmp panic ret -;global isr_handler + isr_handler: + push ebp + mov ebp, esp + +.end: + leave + ret + +isr_common: push ds push es push fs @@ -103,8 +83,8 @@ isr_handler: mov fs, ax mov gs, ax - LOG msg_interrupt - + ;LOG msg_interrupt + call isr_handler ;extern pic_eoi ;call pic_eoi @@ -119,6 +99,29 @@ isr_handler: section .rodata +msg_int_division_zero: db "Division by zero", 0x0 +msg_int_debug: db "Debug", 0x0 +msg_int_nmi: db "Non-maskable interrupt", 0x0 +msg_int_breakpoint: db "Breakpoint", 0x0 +msg_int_overflow: db "Overflow", 0x0 +msg_int_range_exceeded: db "Bound range exceeded", 0x0 +msg_int_invalid_opcode: db "Invalid Opcode", 0x0 +msg_int_device_not_available: db "Device not available", 0x0 +msg_int_double_fault: db "Double fault", 0x0 +msg_int_coproc_segment_overrun: db "Coprocessor segment overrun", 0x0 +msg_int_invalid_tss: db "Invalid TSS", 0x0 +msg_int_seg_not_present: db "Segment not present", 0x0 +msg_int_stack_segfault: db "Stack segment fault", 0x0 +msg_int_gpf: db "General Protection Fault", 0x0 +msg_int_page_fault: db "Page fault", 0x0 +msg_int_reserved: db "Reserved", 0x0 +msg_int_fp_exception: db "x87 Floating-Point Exception", 0x0 +msg_int_align_check: db "Aligment check", 0x0 +msg_int_machine_check: db "Machine check", 0x0 +msg_int_simd_exception: db "SIMD Floating-Point exception", 0x0 +msg_int_virt_exception: db "Virtualization exception", 0x0 +msg_int_sec_exception: db "Security exception", 0x0 + msg_interrupt db "interrupt", 0xA db "edi: %x esi: %x ebp: %x esp: %x", 0xA db "ebx: %x edx: %x ecx: %x eax: %x", 0xA diff --git a/kernel/kernel.s b/kernel/kernel.s index 4b84bd3..3fd7f03 100644 --- a/kernel/kernel.s +++ b/kernel/kernel.s @@ -1,2 +1,12 @@ +; File: kernel.s + [BITS 32] +; Function: kmain +.global kmain +kmain: + push ebp + mov ebp, esp + + leave + ret diff --git a/kernel/multiboot.inc b/kernel/multiboot.inc index 1d82f06..a64f40d 100644 --- a/kernel/multiboot.inc +++ b/kernel/multiboot.inc @@ -1,9 +1,54 @@ -; file: multiboot.inc +; File: multiboot.inc + +; Define: MB_HDR_MAGIC +; Multiboot Header Magic +MB_HDR_MAGIC equ 0x1BADB002 + +; Define: MB_MAGIC +; Multiboot Magic passed by the bootloader. +MB_MAGIC equ 0x2BADB002 + +; Structure: mb_header +; +; .magic - todo +; .flags - See +; .checksum - todo +; .aout_kludge - todo +; .mode_type - todo +; .width - todo +; .height - todo +; .depth - todo +struc mb_header + .magic: resd 1 + .flags: resd 1 + .checksum: resd 1 + .aout_kludge: resd 5 + .mode_type: resd 1 + .width: resd 1 + .height: resd 1 + .depth: resd 1 +endstruc + +; Defines: flags +; +; MB_HDR_ALIGN - todo +; MB_HDR_MEMINFO - +; MB_HDR_VIDEO - todo +MB_HDR_ALIGN equ 1 << 0 +MB_HDR_MEMINFO equ 1 << 1 +MB_HDR_VIDEO equ 1 << 2 ; Structure: mb_info +; +; Fields: +; .flags - See +; .mem_lower - todo +; .mem_upper - todo +; .boot_device - todo +; . struc mb_info - ; Field: flags + ;; flags .flags: resd 1 ;; flags[0] is set @@ -25,7 +70,7 @@ struc mb_info ;; flags[6] is set .mmap_length: resd 1 - ; Field: mmap_addr + ; ; see .mmap_addr: resd 1 @@ -59,6 +104,13 @@ struc mb_info .framebuffer_misc: resw 3 endstruc +; Defines: flags +; +; MB_INFO_MEM - todo +; MB_INFO_BOOTDEV - todo +MB_INFO_MEM equ 1 << 0 +MB_INFO_BOOTDEV equ 1 << 1 + ; Structure: mb_mmap struc mb_mmap .size: resd 1 @@ -67,6 +119,13 @@ struc mb_mmap .type: resd 1 endstruc +; Defines: types +; +; MB_MEMORY_AVAILABLE - 1 +; MB_MEMORY_RESERVED - 2 +; MB_MEMORY_ACPI - 3 +; MB_MEMORY_NVS - 4 +; MB_MEMORY_BADRAM - 5 %define MB_MEMORY_AVAILABLE 1 %define MB_MEMORY_RESERVED 2 %define MB_MEMORY_ACPI 3 diff --git a/kernel/pmm.s b/kernel/pmm.s index d15bd1f..21742fe 100644 --- a/kernel/pmm.s +++ b/kernel/pmm.s @@ -1,3 +1,4 @@ +; File: pmm.s [BITS 32] ;; XXX: align address to page diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000..c5d09e0 --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,3 @@ +SUBDIR = base crypto + +include $(TOPDIR)/share/mk/stupid.subdir.mk diff --git a/lib/base.inc b/lib/base.inc index 2cf3a42..49883fb 100644 --- a/lib/base.inc +++ b/lib/base.inc @@ -9,6 +9,7 @@ extern log_impl ; LOG msg_boot_info, eax ; (end) %macro LOG 1-* +%ifdef DEBUG %rep %0 %rotate -1 push %1 @@ -21,4 +22,5 @@ extern log_impl %rep %0 add esp, 4 %endrep +%endif %endmacro diff --git a/lib/base/Makefile b/lib/base/Makefile new file mode 100644 index 0000000..e99be36 --- /dev/null +++ b/lib/base/Makefile @@ -0,0 +1,4 @@ +LIB = base +SRCS = log.s + +include $(TOPDIR)/share/mk/stupid.lib.mk diff --git a/lib/base/build.mk b/lib/base/build.mk deleted file mode 100644 index 36185ec..0000000 --- a/lib/base/build.mk +++ /dev/null @@ -1,2 +0,0 @@ -LIBS += base -base_SRCS = log.s diff --git a/lib/build.mk b/lib/build.mk deleted file mode 100644 index ff732f3..0000000 --- a/lib/build.mk +++ /dev/null @@ -1,24 +0,0 @@ -LIBS_BIN = - -define LIBS_TEMPLATE - -$(1)_BIN = lib$(1).a - -$(1)_OBJS = $$(addprefix lib/$(1)/, $$($(1)_SRCS:.s=.o)) - -$$($(1)_BIN): $$($(1)_OBJS) - ar rcs $$@ $$^ - -GARBADGE += $$($(1)_OBJS) $$($(1)_BIN) -LIBS_BIN += $$($(1)_BIN) - -endef - -LIBS = - -include lib/*/build.mk - -$(foreach lib, $(LIBS), $(eval $(call LIBS_TEMPLATE,$(lib)))) - -lib/%.o: lib/%.s - $(AS) -felf $(ASFLAGS) -o $@ $< diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile new file mode 100644 index 0000000..1141a51 --- /dev/null +++ b/lib/crypto/Makefile @@ -0,0 +1,4 @@ +LIB = crypto +SRCS = hash/sha256.s + +include $(TOPDIR)/share/mk/stupid.lib.mk diff --git a/lib/pls/std/error.pls b/lib/pls/std/error.pls new file mode 100644 index 0000000..35bec1b --- /dev/null +++ b/lib/pls/std/error.pls @@ -0,0 +1,5 @@ +CLASS Error; + +MESSAGE + +END; diff --git a/lib/pls/std/io/file.pls b/lib/pls/std/io/file.pls new file mode 100644 index 0000000..f05306e --- /dev/null +++ b/lib/pls/std/io/file.pls @@ -0,0 +1,3 @@ +CLASS File; + +END; diff --git a/share/mk/stupid.clean.mk b/share/mk/stupid.clean.mk new file mode 100644 index 0000000..032e219 --- /dev/null +++ b/share/mk/stupid.clean.mk @@ -0,0 +1,5 @@ +# File: stupid.clean.mk +# + +clean: + $(RM) $(CLEANFILES) diff --git a/share/mk/stupid.kernel.mk b/share/mk/stupid.kernel.mk new file mode 100644 index 0000000..32d4805 --- /dev/null +++ b/share/mk/stupid.kernel.mk @@ -0,0 +1,38 @@ +# File: stupid.kernel.mk +# +include $(TOPDIR)/share/mk/stupid.own.mk + +ifdef KERNEL + +ASFLAGS += -D__KERNEL__ -I$(TOPDIR)/kernel + +OBJS = $(addsuffix .o, $(basename $(SRCS))) +OBJS-dbg = $(addsuffix .dbg.o, $(basename $(SRCS))) + +CLEANFILES += $(KERNEL) $(KERNEL)-dbg $(OBJS) $(OBJS-dbg) + +$(KERNEL): $(OBJS) + $(LD) -T $(TOPDIR)/kernel/linker.ld -nostdlib -o $@ $^ + +$(KERNEL)-dbg: $(OBJS-dbg) + $(LD) -T $(TOPDIR)/kernel/linker.ld -nostdlib -o $@ $^ + +%.o: %.s + $(AS) $(ASFLAGS) -o $@ $< + +%.dbg.o: %.s + $(AS) $(ASFLAGS) $(ASDBGFLAGS) -o $@ $< + +lib/%.o: ../lib/base/%.s + @$(MKCWD) + $(AS) $(ASFLAGS) -o $@ $< + +lib/%.dbg.o: ../lib/base/%.s + @$(MKCWD) + $(AS) $(ASFLAGS) $(ASDBGFLAGS) -o $@ $< + +all: $(KERNEL) $(KERNEL)-dbg + +endif + +include $(TOPDIR)/share/mk/stupid.clean.mk diff --git a/share/mk/stupid.lib.mk b/share/mk/stupid.lib.mk new file mode 100644 index 0000000..6601e4b --- /dev/null +++ b/share/mk/stupid.lib.mk @@ -0,0 +1,33 @@ +# File: stupid.lib.mk +# Support for building libraries + +include $(TOPDIR)/share/mk/stupid.own.mk + +ifdef LIB + +CLEANFILES += lib$(LIB).a + +ifdef SRCS + +OBJS += $(addsuffix .o, $(basename $(SRCS))) + +CLEANFILES += $(OBJS) + +lib$(LIB).a: $(OBJS) + $(AR) rcs $@ $^ + +else + +CLEANFILES += $(LIB).o + +lib$(LIB).a: $(LIB).o + $(AR) rcs $@ $^ + +endif + +all: lib$(LIB).a + +endif + +include $(TOPDIR)/share/mk/stupid.clean.mk +include $(TOPDIR)/share/mk/stupid.sys.mk diff --git a/share/mk/stupid.own.mk b/share/mk/stupid.own.mk new file mode 100644 index 0000000..084e86c --- /dev/null +++ b/share/mk/stupid.own.mk @@ -0,0 +1,32 @@ +# File: stupid.own.mk +# Define common variables +ifndef _STUPID_OWN_MK_ +_STUPID_OWN_MK_=1 + +.DEFAULT_GOAL := all + +BINDIR = /bin +LIBDIR = /lib + +CC = clang -target i386-none-elf +CXX = clang++ -target i386-none-elf + +AS = nasm +LD = ld.lld +PLSCC = plsc +OBJCOPY = llvm-objcopy +OBJDUMP = llvm-objdump + +MKCWD = mkdir -p $(@D) + +TARGETS = all clean install +.PHONY: $(TARGETS) + +EXTRAFLAGS = -DSTUPID_VERSION="0.0" -D__STUPID__ + +CFLAGS += -Wall -Werror -Wextra $(EXTRAFLAGS) +CXXFLAGS += -Wall -Werror -Wextra $(EXTRAFLAGS) +ASFLAGS += -felf -I$(TOPDIR)/lib $(EXTRAFLAGS) +ASDBGFLAGS += -F dwarf -g -DDEBUG + +endif diff --git a/share/mk/stupid.prog.mk b/share/mk/stupid.prog.mk new file mode 100644 index 0000000..abbfa91 --- /dev/null +++ b/share/mk/stupid.prog.mk @@ -0,0 +1,41 @@ +# File: stupid.prog.mk +# Building programs from source files +# +# targets: +# - all: +# build the program and its manual page. +# - clean: +# remove the program and any object files. +# - install: +# install the program and its manual page. + +include $(TOPDIR)/share/mk/stupid.own.mk + +ifdef PROG + +CLEANFILES += $(PROG) + +ifdef SRCS + +OBJS += $(addsuffix .o, $(basename $(SRCS))) + +CLEANFILES += $(OBJS) + +$(PROG): $(OBJS) + $(CC) $(CFLAGS) -o $@ $^ $(LDADD) + +else + +CLEANFILES += $(PROG).o + +$(PROG): $(PROG).o + $(CC) $(CFLAGS) -o $@ $< $(LDADD) + +endif + +all: $(PROG) + +endif + +include $(TOPDIR)/share/mk/stupid.clean.mk +include $(TOPDIR)/share/mk/stupid.sys.mk diff --git a/share/mk/stupid.subdir.mk b/share/mk/stupid.subdir.mk new file mode 100644 index 0000000..05eba99 --- /dev/null +++ b/share/mk/stupid.subdir.mk @@ -0,0 +1,20 @@ +# File: stupid.subdir.mk +# Targets for building subdirectories + +.DEFAULT_GOAL := all +TOPGOALS = all clean install + +ifndef NOSUBDIR + +.PHONY: $(SUBDIR) +$(SUBDIR): + $(MAKE) -C $@ $(MAKECMDGOALS) + +$(TOPGOALS): $(SUBDIR) + +else + +# ensure target exist +$(TOPGOALS): + +endif diff --git a/share/mk/stupid.sys.mk b/share/mk/stupid.sys.mk new file mode 100644 index 0000000..dc7f4bc --- /dev/null +++ b/share/mk/stupid.sys.mk @@ -0,0 +1,19 @@ +# File: stupid.sys.mk + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) + +%.o: %.cc + $(CXX) -c -o $@ $< $(CXXFLAGS) + +%.o: %.cpp + $(CXX) -c -o $@ $< $(CXXFLAGS) + +%.o: %.cxx + $(CXX) -c -o $@ $< $(CXXFLAGS) + +%.o: %.C + $(CXX) -c -o $@ $< $(CXXFLAGS) + +%.o: %.s + $(AS) $(ASFLAGS) -o $@ $< diff --git a/thirdparty/Makefile b/thirdparty/Makefile new file mode 100644 index 0000000..44f981f --- /dev/null +++ b/thirdparty/Makefile @@ -0,0 +1,3 @@ +NOSUBDIR := 1 + +include $(TOPDIR)/share/mk/stupid.subdir.mk diff --git a/tools/build.mk b/tools/build.mk deleted file mode 100644 index f3e8494..0000000 --- a/tools/build.mk +++ /dev/null @@ -1,9 +0,0 @@ -define TOOLS_TEMPLATE - -$(1) = $$(addprefix $$(TOOLS_DIR)/, $$(shell echo -n $(1) | tr A-Z a-z)) - -endef - -TOOLS = GIT-VERSION CREATE-ISO - -$(foreach tool, $(TOOLS), $(eval $(call TOOLS_TEMPLATE,$(tool)))) diff --git a/tools/create-iso b/tools/create-iso index bb78770..ad63a34 100755 --- a/tools/create-iso +++ b/tools/create-iso @@ -12,6 +12,12 @@ menuentry "StupidOS" { boot } +menuentry "StupidOS (debug)" { + hashsum --hash sha256 --check /boot/hashfile --prefix / + multiboot /vmstupid-dbg "lang=en" + boot +} + EOF ) @@ -19,6 +25,7 @@ gen_iso_file() { mkdir -p "$2/boot/grub" echo "$grub_config" > "$2/boot/grub/grub.cfg" sha256sum vmstupid > "$2/boot/hashfile" + sha256sum vmstupid-dbg >> "$2/boot/hashfile" grub-mkrescue -o $1 $2 }