refactor: rework the entire build system
This commit is contained in:
		
							parent
							
								
									4e110d12eb
								
							
						
					
					
						commit
						8cefd7946f
					
				
					 41 changed files with 607 additions and 209 deletions
				
			
		
							
								
								
									
										6
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							|  | @ -9,6 +9,7 @@ | ||||||
| *.a | *.a | ||||||
| *.dump | *.dump | ||||||
| vmstupid | vmstupid | ||||||
|  | vmstupid-dbg | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| /sysroot | /sysroot | ||||||
|  | @ -17,3 +18,8 @@ log.txt | ||||||
| 
 | 
 | ||||||
| /docs/html | /docs/html | ||||||
| /docs/config/Data | /docs/config/Data | ||||||
|  | 
 | ||||||
|  | a.out | ||||||
|  | *.old | ||||||
|  | /bx_enh_dbg.ini | ||||||
|  | bochsrc.bxrc | ||||||
|  |  | ||||||
							
								
								
									
										58
									
								
								Makefile
									
										
									
									
									
								
							
							
						
						
									
										58
									
								
								Makefile
									
										
									
									
									
								
							|  | @ -1,53 +1,13 @@ | ||||||
| .SUFFIXES: |  | ||||||
| .DELETE_ON_ERROR: |  | ||||||
| .DEFAULT_GOAL := all | .DEFAULT_GOAL := all | ||||||
|  | TOPDIR	:= $(CURDIR) | ||||||
|  | export TOPDIR | ||||||
| 
 | 
 | ||||||
| AS		= nasm | SUBDIR := thirdparty lib bin kernel | ||||||
| LD		= ld.lld |  | ||||||
| OBJDUMP = llvm-objdump |  | ||||||
| QEMU	= qemu-system-i386 |  | ||||||
| RM		= rm -f |  | ||||||
| MKCWD	= mkdir -p $(@D) |  | ||||||
| INSTALL = install |  | ||||||
| 
 | 
 | ||||||
| BIN_DIR		= bin | .PHONY: docs | ||||||
| DOC_DIR		= docs | docs: | ||||||
| KERNEL_DIR	= kernel | 	-mkdir -p docs/html | ||||||
| LIB_DIR		= lib | 	naturaldocs -p docs/config -img docs/img -xi tmp -i . -o HTML docs/html | ||||||
| TOOLS_DIR	= tools | 	cp docs/img/favicon.ico docs/html/ | ||||||
| 
 | 
 | ||||||
| include $(TOOLS_DIR)/build.mk | include $(TOPDIR)/share/mk/stupid.subdir.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 |  | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								bin/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								bin/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | NOSUBDIR := 1 | ||||||
|  | 
 | ||||||
|  | include $(TOPDIR)/share/mk/stupid.subdir.mk | ||||||
|  | @ -3,14 +3,26 @@ | ||||||
|  */ |  */ | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
|  * Procedure: Motd |  * Procedure: main | ||||||
|  * Program entry point |  * | ||||||
|  |  * 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; | 	END; | ||||||
| 	CLOSE FILE(in); | 
 | ||||||
|  | 	[in release]; | ||||||
|  | 	[now release]; | ||||||
| END; | END; | ||||||
|  |  | ||||||
|  | @ -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/ |  | ||||||
							
								
								
									
										2
									
								
								docs/coding-style.txt
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								docs/coding-style.txt
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,2 @@ | ||||||
|  | File: Coding Style | ||||||
|  | 
 | ||||||
|  | @ -116,6 +116,7 @@ Format: 1.51 | ||||||
| Alter Language: Assembly | Alter Language: Assembly | ||||||
| 
 | 
 | ||||||
|    Add Extensions: s inc |    Add Extensions: s inc | ||||||
|  |    Struct Prototype Ender: endstruc | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Language: PL/S | Language: PL/S | ||||||
|  |  | ||||||
|  | @ -40,6 +40,7 @@ Timestamp: Updated yyyy/mm/dd | ||||||
| 
 | 
 | ||||||
| File: Introduction  (docs/intro.txt) | File: Introduction  (docs/intro.txt) | ||||||
| Link: Source Code  (https://github.com/d0p1s4m4/StupidOS) | Link: Source Code  (https://github.com/d0p1s4m4/StupidOS) | ||||||
|  | File: Coding Style  (docs/coding-style.txt) | ||||||
| File: FAQ  (docs/faq.txt) | File: FAQ  (docs/faq.txt) | ||||||
| 
 | 
 | ||||||
| Group: Kernel  { | Group: Kernel  { | ||||||
|  | @ -56,11 +57,9 @@ Group: Kernel  { | ||||||
|       File: serial.s  (no auto-title, kernel/drivers/serial.s) |       File: serial.s  (no auto-title, kernel/drivers/serial.s) | ||||||
|       }  # Group: Driver |       }  # Group: Driver | ||||||
| 
 | 
 | ||||||
|    Group: Debug  { |    File: kernel.s  (kernel/kernel.s) | ||||||
| 
 |    File: msg_en  (kernel/i18n/msg_en.s) | ||||||
|       File: msg_en  (kernel/debug/msg_en.s) |    File: pmm.s  (kernel/pmm.s) | ||||||
|       }  # Group: Debug |  | ||||||
| 
 |  | ||||||
|    }  # Group: Kernel |    }  # Group: Kernel | ||||||
| 
 | 
 | ||||||
| Group: Lib  { | Group: Lib  { | ||||||
|  | @ -107,6 +106,21 @@ Group: Bin  { | ||||||
| 
 | 
 | ||||||
|    }  # 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  { | Group: Index  { | ||||||
| 
 | 
 | ||||||
|    Index: Everything |    Index: Everything | ||||||
|  |  | ||||||
|  | @ -79,3 +79,18 @@ Format: 1.51 | ||||||
| # If you add something that you think would be useful to other developers | # 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 | # and should be included in Natural Docs by default, please e-mail it to | ||||||
| # topics [at] naturaldocs [dot] org. | # topics [at] naturaldocs [dot] org. | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Alter Topic Type: Macro | ||||||
|  | 
 | ||||||
|  |    Add Keywords: | ||||||
|  |       equ | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | Topic Type: Struct | ||||||
|  | 
 | ||||||
|  |    Plural: Structs | ||||||
|  |    Class Hierarchy: Yes | ||||||
|  | 
 | ||||||
|  |    Keywords: | ||||||
|  |       struc | ||||||
|  |  | ||||||
							
								
								
									
										5
									
								
								kernel/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								kernel/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
|  | @ -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) |  | ||||||
| 
 |  | ||||||
							
								
								
									
										51
									
								
								kernel/cpu.inc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								kernel/cpu.inc
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
|  | 
 | ||||||
|  | @ -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 |  | ||||||
|  | @ -1,2 +0,0 @@ | ||||||
| DRIVERS_SRCS	= serial.s |  | ||||||
| DRIVERS_OBJS	= $(addprefix drivers/, $(DRIVERS_SRCS:.s=.o)) |  | ||||||
							
								
								
									
										14
									
								
								kernel/fs/vfs.inc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								kernel/fs/vfs.inc
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
|  | @ -5,16 +5,22 @@ | ||||||
| %include "base.inc" | %include "base.inc" | ||||||
| %include "multiboot.inc" | %include "multiboot.inc" | ||||||
| 
 | 
 | ||||||
| MULTIBOOT_MAGIC equ 0x1BADB002 | ; Define: MB_HDR_FLAGS 
 | ||||||
| MULTIBOOT_ALIGN equ 1 << 0 | MB_HDR_FLAGS equ MB_HDR_ALIGN | MB_HDR_MEMINFO | MB_HDR_VIDEO | ||||||
| MULTIBOOT_MEMINFO equ 1 << 1 |  | ||||||
| MULTIBOOT_FLAGS equ MULTIBOOT_ALIGN | MULTIBOOT_MEMINFO |  | ||||||
| 
 | 
 | ||||||
| section .multiboot | section .multiboot | ||||||
| align 4 | align 4 | ||||||
| 	dd MULTIBOOT_MAGIC | 	istruc mb_header | ||||||
| 	dd MULTIBOOT_FLAGS | 		at mb_header.magic,    dd MB_HDR_MAGIC | ||||||
| 	dd -(MULTIBOOT_MAGIC + MULTIBOOT_FLAGS) | 		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 | section .bss | ||||||
| align 16 | align 16 | ||||||
|  | @ -25,6 +31,7 @@ stack_top: | ||||||
| section .text | section .text | ||||||
| 
 | 
 | ||||||
| 	; Function: entry
 | 	; Function: entry
 | ||||||
|  | 	; setup cpu and paging before calling <kmain>
 | ||||||
| 	;
 | 	;
 | ||||||
| 	; in:
 | 	; in:
 | ||||||
| 	;     EAX - Multiboot magic
 | 	;     EAX - Multiboot magic
 | ||||||
|  | @ -36,18 +43,17 @@ section .text | ||||||
| global entry | global entry | ||||||
| entry: | entry: | ||||||
| 	mov esp, stack_top | 	mov esp, stack_top | ||||||
| 	cli | 	cli ; disable interrupt
 | ||||||
| 
 | 
 | ||||||
| 	mov edi, eax | 	mov edi, eax ; save multiboot magic in EDI
 | ||||||
| 	mov esi, ebx | 	mov esi, ebx ; save multiboot structure in ESI
 | ||||||
| 
 | 
 | ||||||
| 	;; initialize serial (mostly used for debug)
 | 	;; initialize serial (mostly used for debug)
 | ||||||
| 	extern serial_init | 	extern serial_init | ||||||
| 	call serial_init | 	call serial_init | ||||||
| 
 | 
 | ||||||
| 	;; eax <- magic
 | 	;; make sure we use a multiboot compliant bootloader
 | ||||||
| 	;; ebx <- multiboot struct
 | 	cmp edi, MB_MAGIC | ||||||
| 	cmp edi, 0x2BADB002 |  | ||||||
| 	je .multiboot_valid | 	je .multiboot_valid | ||||||
| 
 | 
 | ||||||
| 	LOG err_invalid_boot_magic, edi | 	LOG err_invalid_boot_magic, edi | ||||||
|  | @ -95,7 +101,7 @@ hang: | ||||||
| 	 | 	 | ||||||
| section .rodata | 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_boot_info db "Bootloader: %s", 0 | ||||||
| msg_pmm_initialized db "PMM initialized", 0 | msg_pmm_initialized db "PMM initialized", 0 | ||||||
| err_invalid_boot_magic db "[ERROR] Invalid boot magic (got: %x, expected: 0x2BADB002)", 0 | err_invalid_boot_magic db "[ERROR] Invalid boot magic (got: %x, expected: 0x2BADB002)", 0 | ||||||
|  |  | ||||||
							
								
								
									
										10
									
								
								kernel/i18n/i18n.inc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								kernel/i18n/i18n.inc
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										102
									
								
								kernel/i18n/msg_en.s
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										102
									
								
								kernel/i18n/msg_en.s
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										71
									
								
								kernel/isr.s
									
										
									
									
									
								
							
							
						
						
									
										71
									
								
								kernel/isr.s
									
										
									
									
									
								
							|  | @ -1,5 +1,6 @@ | ||||||
| [BITS 32] | [BITS 32] | ||||||
| 
 | 
 | ||||||
|  | %include "cpu.inc" | ||||||
| %include "base.inc" | %include "base.inc" | ||||||
| 
 | 
 | ||||||
| %macro ISR_NO_ERR 1 | %macro ISR_NO_ERR 1 | ||||||
|  | @ -8,7 +9,7 @@ isr%1: | ||||||
| 	xchg bx, bx | 	xchg bx, bx | ||||||
| 	push dword 0 | 	push dword 0 | ||||||
| 	push dword %1 | 	push dword %1 | ||||||
| 	jmp isr_handler | 	jmp isr_common | ||||||
| %endmacro | %endmacro | ||||||
| 
 | 
 | ||||||
| %macro ISR_ERR 1 | %macro ISR_ERR 1 | ||||||
|  | @ -16,38 +17,9 @@ global isr%1 | ||||||
| isr%1: | isr%1: | ||||||
| 	xchg bx, bx | 	xchg bx, bx | ||||||
| 	push dword %1 | 	push dword %1 | ||||||
| 	jmp isr_handler | 	jmp isr_common | ||||||
| %endmacro	 | %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	 |  | ||||||
| 	 |  | ||||||
| section .text | section .text | ||||||
| 
 | 
 | ||||||
| ISR_NO_ERR 0 | ISR_NO_ERR 0 | ||||||
|  | @ -89,8 +61,16 @@ panic: | ||||||
| 	;jmp panic
 | 	;jmp panic
 | ||||||
| 	ret | 	ret | ||||||
| 
 | 
 | ||||||
| ;global isr_handler
 | 
 | ||||||
| isr_handler: | isr_handler: | ||||||
|  | 	push ebp | ||||||
|  | 	mov ebp, esp | ||||||
|  | 
 | ||||||
|  | .end: | ||||||
|  | 	leave | ||||||
|  | 	ret | ||||||
|  | 
 | ||||||
|  | isr_common: | ||||||
| 	push ds | 	push ds | ||||||
| 	push es | 	push es | ||||||
| 	push fs | 	push fs | ||||||
|  | @ -103,8 +83,8 @@ isr_handler: | ||||||
| 	mov fs, ax | 	mov fs, ax | ||||||
| 	mov gs, ax | 	mov gs, ax | ||||||
| 
 | 
 | ||||||
| 	LOG msg_interrupt | 	;LOG msg_interrupt
 | ||||||
| 
 | 	call isr_handler | ||||||
| 	;extern pic_eoi
 | 	;extern pic_eoi
 | ||||||
| 	;call pic_eoi
 | 	;call pic_eoi
 | ||||||
| 	 | 	 | ||||||
|  | @ -119,6 +99,29 @@ isr_handler: | ||||||
| 
 | 
 | ||||||
| section .rodata | 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 | msg_interrupt db "interrupt", 0xA | ||||||
| 	db "edi: %x esi: %x ebp: %x esp: %x", 0xA | 	db "edi: %x esi: %x ebp: %x esp: %x", 0xA | ||||||
| 	db "ebx: %x edx: %x ecx: %x eax: %x", 0xA | 	db "ebx: %x edx: %x ecx: %x eax: %x", 0xA | ||||||
|  |  | ||||||
|  | @ -1,2 +1,12 @@ | ||||||
|  | ; File: kernel.s
 | ||||||
|  | 
 | ||||||
| [BITS 32] | [BITS 32] | ||||||
| 
 | 
 | ||||||
|  | ; Function: kmain
 | ||||||
|  | .global kmain
 | ||||||
|  | kmain: | ||||||
|  | 	push ebp | ||||||
|  | 	mov ebp, esp | ||||||
|  | 
 | ||||||
|  | 	leave | ||||||
|  | 	ret | ||||||
|  |  | ||||||
|  | @ -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 <flags> | ||||||
|  | ; .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_info.mem_lower> | ||||||
|  | ; 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 | ; Structure: mb_info | ||||||
|  | ;  | ||||||
|  | ; Fields: | ||||||
|  | ; .flags       - See <flags> | ||||||
|  | ; .mem_lower   - todo | ||||||
|  | ; .mem_upper   - todo | ||||||
|  | ; .boot_device - todo | ||||||
|  | ;    . | ||||||
| struc mb_info | struc mb_info | ||||||
| 
 | 
 | ||||||
| 	; Field: flags | 	;; flags | ||||||
| 	.flags: resd 1 | 	.flags: resd 1 | ||||||
| 
 | 
 | ||||||
| 	;; flags[0] is set | 	;; flags[0] is set | ||||||
|  | @ -25,7 +70,7 @@ struc mb_info | ||||||
| 
 | 
 | ||||||
| 	;; flags[6] is set | 	;; flags[6] is set | ||||||
| 	.mmap_length: resd 1 | 	.mmap_length: resd 1 | ||||||
| 	; Field: mmap_addr | 	; <mb_info.mmap_length> | ||||||
| 	; see <mb_mmap> | 	; see <mb_mmap> | ||||||
| 	.mmap_addr: resd 1 | 	.mmap_addr: resd 1 | ||||||
| 
 | 
 | ||||||
|  | @ -59,6 +104,13 @@ struc mb_info | ||||||
| 	.framebuffer_misc: resw 3 | 	.framebuffer_misc: resw 3 | ||||||
| endstruc | 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 | ; Structure: mb_mmap | ||||||
| struc mb_mmap | struc mb_mmap | ||||||
| 	.size: resd 1 | 	.size: resd 1 | ||||||
|  | @ -67,6 +119,13 @@ struc mb_mmap | ||||||
| 	.type: resd 1 | 	.type: resd 1 | ||||||
| endstruc | 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_AVAILABLE 1 | ||||||
| %define MB_MEMORY_RESERVED 2 | %define MB_MEMORY_RESERVED 2 | ||||||
| %define MB_MEMORY_ACPI 3 | %define MB_MEMORY_ACPI 3 | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
|  | ; File: pmm.s
 | ||||||
| [BITS 32] | [BITS 32] | ||||||
| 	;; XXX: align address to page
 | 	;; XXX: align address to page
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								lib/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								lib/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | SUBDIR = base crypto | ||||||
|  | 
 | ||||||
|  | include $(TOPDIR)/share/mk/stupid.subdir.mk | ||||||
|  | @ -9,6 +9,7 @@ extern log_impl | ||||||
| ; LOG msg_boot_info, eax | ; LOG msg_boot_info, eax | ||||||
| ; (end) | ; (end) | ||||||
| %macro LOG 1-* | %macro LOG 1-* | ||||||
|  | %ifdef DEBUG | ||||||
| %rep %0 | %rep %0 | ||||||
| %rotate -1 | %rotate -1 | ||||||
| 	push %1 | 	push %1 | ||||||
|  | @ -21,4 +22,5 @@ extern log_impl | ||||||
| %rep %0 | %rep %0 | ||||||
| 	add esp, 4 | 	add esp, 4 | ||||||
| %endrep | %endrep | ||||||
|  | %endif | ||||||
| %endmacro | %endmacro | ||||||
|  |  | ||||||
							
								
								
									
										4
									
								
								lib/base/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								lib/base/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | LIB = base | ||||||
|  | SRCS = log.s | ||||||
|  | 
 | ||||||
|  | include $(TOPDIR)/share/mk/stupid.lib.mk | ||||||
|  | @ -1,2 +0,0 @@ | ||||||
| LIBS		+= base |  | ||||||
| base_SRCS	= log.s |  | ||||||
							
								
								
									
										24
									
								
								lib/build.mk
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								lib/build.mk
									
										
									
									
									
								
							|  | @ -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 $@ $< |  | ||||||
							
								
								
									
										4
									
								
								lib/crypto/Makefile
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								lib/crypto/Makefile
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | LIB		= crypto | ||||||
|  | SRCS	= hash/sha256.s | ||||||
|  | 
 | ||||||
|  | include $(TOPDIR)/share/mk/stupid.lib.mk | ||||||
							
								
								
									
										5
									
								
								lib/pls/std/error.pls
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								lib/pls/std/error.pls
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | CLASS Error; | ||||||
|  | 
 | ||||||
|  | MESSAGE  | ||||||
|  | 
 | ||||||
|  | END; | ||||||
							
								
								
									
										3
									
								
								lib/pls/std/io/file.pls
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								lib/pls/std/io/file.pls
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | CLASS File; | ||||||
|  | 
 | ||||||
|  | END; | ||||||
							
								
								
									
										5
									
								
								share/mk/stupid.clean.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								share/mk/stupid.clean.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,5 @@ | ||||||
|  | # File: stupid.clean.mk
 | ||||||
|  | #
 | ||||||
|  | 
 | ||||||
|  | clean: | ||||||
|  | 	$(RM) $(CLEANFILES) | ||||||
							
								
								
									
										38
									
								
								share/mk/stupid.kernel.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								share/mk/stupid.kernel.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										33
									
								
								share/mk/stupid.lib.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								share/mk/stupid.lib.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										32
									
								
								share/mk/stupid.own.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										32
									
								
								share/mk/stupid.own.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										41
									
								
								share/mk/stupid.prog.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								share/mk/stupid.prog.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										20
									
								
								share/mk/stupid.subdir.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								share/mk/stupid.subdir.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 | ||||||
							
								
								
									
										19
									
								
								share/mk/stupid.sys.mk
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								share/mk/stupid.sys.mk
									
										
									
									
									
										Normal file
									
								
							|  | @ -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 $@ $< | ||||||
							
								
								
									
										3
									
								
								thirdparty/Makefile
									
										
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								thirdparty/Makefile
									
										
									
									
										vendored
									
									
										Normal file
									
								
							|  | @ -0,0 +1,3 @@ | ||||||
|  | NOSUBDIR := 1 | ||||||
|  | 
 | ||||||
|  | include $(TOPDIR)/share/mk/stupid.subdir.mk | ||||||
|  | @ -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)))) |  | ||||||
|  | @ -12,6 +12,12 @@ menuentry "StupidOS" { | ||||||
|    boot |    boot | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | menuentry "StupidOS (debug)" { | ||||||
|  | 	hashsum --hash sha256 --check /boot/hashfile --prefix / | ||||||
|  | 	multiboot /vmstupid-dbg "lang=en" | ||||||
|  | 	boot | ||||||
|  | } | ||||||
|  | 
 | ||||||
| EOF | EOF | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
|  | @ -19,6 +25,7 @@ gen_iso_file() { | ||||||
| 	mkdir -p "$2/boot/grub" | 	mkdir -p "$2/boot/grub" | ||||||
| 	echo "$grub_config" > "$2/boot/grub/grub.cfg" | 	echo "$grub_config" > "$2/boot/grub/grub.cfg" | ||||||
| 	sha256sum vmstupid > "$2/boot/hashfile" | 	sha256sum vmstupid > "$2/boot/hashfile" | ||||||
|  | 	sha256sum vmstupid-dbg >> "$2/boot/hashfile" | ||||||
| 
 | 
 | ||||||
| 	grub-mkrescue -o $1 $2 | 	grub-mkrescue -o $1 $2 | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue