From 8e77928997a2828555279a08433dfacf26df071c Mon Sep 17 00:00:00 2001 From: d0p1 Date: Wed, 17 May 2023 09:51:10 +0200 Subject: [PATCH] ci: build and publish documentation --- .github/workflows/doc.yml | 24 ++++++++ .gitignore | 3 + Makefile | 5 +- docs/build.mk | 4 ++ docs/config/Languages.txt | 118 ++++++++++++++++++++++++++++++++++++++ docs/config/Menu.txt | 76 ++++++++++++++++++++++++ kernel/drivers/serial.s | 16 ++++++ kernel/head.s | 12 ++++ kernel/idt.s | 5 +- kernel/isr.s | 83 ++++++++++++++++++++------- kernel/multiboot.inc | 2 + kernel/paging.s | 10 +++- kernel/pic.s | 16 ++++++ kernel/pmm.s | 20 +++++-- lib/base.inc | 2 + lib/build.mk | 2 +- 16 files changed, 366 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/doc.yml create mode 100644 docs/build.mk create mode 100644 docs/config/Languages.txt create mode 100644 docs/config/Menu.txt diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml new file mode 100644 index 0000000..bd876b5 --- /dev/null +++ b/.github/workflows/doc.yml @@ -0,0 +1,24 @@ + +name: Docs + +on: [push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install build-essential naturaldocs + - name: Build + run: | + make docs + - name: Deploy + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./docs/html + cname: stupidos.d0p1.eu + diff --git a/.gitignore b/.gitignore index af758fc..fa7e052 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,6 @@ vmstupid /sysroot log.txt + +/docs/html +/docs/config/Data diff --git a/Makefile b/Makefile index 6f4676f..fbb1715 100644 --- a/Makefile +++ b/Makefile @@ -18,16 +18,17 @@ TOOLS_DIR = tools include $(TOOLS_DIR)/build.mk -ASFLAGS = -DSTUPID_VERSION="\"$(shell $(GIT-VERSION))\"" -Ilib \ +ASFLAGS = -F dwarf -g -DSTUPID_VERSION="\"$(shell $(GIT-VERSION))\"" -Ilib \ -DBUILD_DATE="\"$(shell date --iso)\"" \ -DNASM_VERSION="\"$(shell nasm -v)\"" -QEMUFLAGS = -serial stdio +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 diff --git a/docs/build.mk b/docs/build.mk new file mode 100644 index 0000000..cef76f9 --- /dev/null +++ b/docs/build.mk @@ -0,0 +1,4 @@ +.PHONY: docs +docs: + -mkdir -p $(DOC_DIR)/html + naturaldocs -p $(DOC_DIR)/config -i . -o HTML $(DOC_DIR)/html diff --git a/docs/config/Languages.txt b/docs/config/Languages.txt new file mode 100644 index 0000000..afc8506 --- /dev/null +++ b/docs/config/Languages.txt @@ -0,0 +1,118 @@ +Format: 1.51 + +# This is the Natural Docs languages file for this project. If you change +# anything here, it will apply to THIS PROJECT ONLY. If you'd like to change +# something for all your projects, edit the Languages.txt in Natural Docs' +# Config directory instead. + + +# You can prevent certain file extensions from being scanned like this: +# Ignore Extensions: [extension] [extension] ... + + +#------------------------------------------------------------------------------- +# SYNTAX: +# +# Unlike other Natural Docs configuration files, in this file all comments +# MUST be alone on a line. Some languages deal with the # character, so you +# cannot put comments on the same line as content. +# +# Also, all lists are separated with spaces, not commas, again because some +# languages may need to use them. +# +# Language: [name] +# Alter Language: [name] +# Defines a new language or alters an existing one. Its name can use any +# characters. If any of the properties below have an add/replace form, you +# must use that when using Alter Language. +# +# The language Shebang Script is special. It's entry is only used for +# extensions, and files with those extensions have their shebang (#!) lines +# read to determine the real language of the file. Extensionless files are +# always treated this way. +# +# The language Text File is also special. It's treated as one big comment +# so you can put Natural Docs content in them without special symbols. Also, +# if you don't specify a package separator, ignored prefixes, or enum value +# behavior, it will copy those settings from the language that is used most +# in the source tree. +# +# Extensions: [extension] [extension] ... +# [Add/Replace] Extensions: [extension] [extension] ... +# Defines the file extensions of the language's source files. You can +# redefine extensions found in the main languages file. You can use * to +# mean any undefined extension. +# +# Shebang Strings: [string] [string] ... +# [Add/Replace] Shebang Strings: [string] [string] ... +# Defines a list of strings that can appear in the shebang (#!) line to +# designate that it's part of the language. You can redefine strings found +# in the main languages file. +# +# Ignore Prefixes in Index: [prefix] [prefix] ... +# [Add/Replace] Ignored Prefixes in Index: [prefix] [prefix] ... +# +# Ignore [Topic Type] Prefixes in Index: [prefix] [prefix] ... +# [Add/Replace] Ignored [Topic Type] Prefixes in Index: [prefix] [prefix] ... +# Specifies prefixes that should be ignored when sorting symbols in an +# index. Can be specified in general or for a specific topic type. +# +#------------------------------------------------------------------------------ +# For basic language support only: +# +# Line Comments: [symbol] [symbol] ... +# Defines a space-separated list of symbols that are used for line comments, +# if any. +# +# Block Comments: [opening sym] [closing sym] [opening sym] [closing sym] ... +# Defines a space-separated list of symbol pairs that are used for block +# comments, if any. +# +# Package Separator: [symbol] +# Defines the default package separator symbol. The default is a dot. +# +# [Topic Type] Prototype Enders: [symbol] [symbol] ... +# When defined, Natural Docs will attempt to get a prototype from the code +# immediately following the topic type. It stops when it reaches one of +# these symbols. Use \n for line breaks. +# +# Line Extender: [symbol] +# Defines the symbol that allows a prototype to span multiple lines if +# normally a line break would end it. +# +# Enum Values: [global|under type|under parent] +# Defines how enum values are referenced. The default is global. +# global - Values are always global, referenced as 'value'. +# under type - Values are under the enum type, referenced as +# 'package.enum.value'. +# under parent - Values are under the enum's parent, referenced as +# 'package.value'. +# +# Perl Package: [perl package] +# Specifies the Perl package used to fine-tune the language behavior in ways +# too complex to do in this file. +# +#------------------------------------------------------------------------------ +# For full language support only: +# +# Full Language Support: [perl package] +# Specifies the Perl package that has the parsing routines necessary for full +# language support. +# +#------------------------------------------------------------------------------- + +# The following languages are defined in the main file, if you'd like to alter +# them: +# +# Text File, Shebang Script, C/C++, C#, Java, JavaScript, Perl, Python, +# PHP, SQL, Visual Basic, Pascal, Assembly, Ada, Tcl, Ruby, Makefile, +# ActionScript, ColdFusion, R, Fortran + +# If you add a language that you think would be useful to other developers +# and should be included in Natural Docs by default, please e-mail it to +# languages [at] naturaldocs [dot] org. + + +Alter Language: Assembly + + Add Extensions: s inc diff --git a/docs/config/Menu.txt b/docs/config/Menu.txt new file mode 100644 index 0000000..013db22 --- /dev/null +++ b/docs/config/Menu.txt @@ -0,0 +1,76 @@ +Format: 1.51 + + +Title: StupidOS + +# You can also add a sub-title to your menu like this: +# SubTitle: [subtitle] + +# You can add a footer to your documentation like this: +# Footer: [text] +# If you want to add a copyright notice, this would be the place to do it. +Timestamp: Updated yyyy/mm/dd +# m - One or two digit month. January is "1" +# mm - Always two digit month. January is "01" +# mon - Short month word. January is "Jan" +# month - Long month word. January is "January" +# d - One or two digit day. 1 is "1" +# dd - Always two digit day. 1 is "01" +# day - Day with letter extension. 1 is "1st" +# yy - Two digit year. 2006 is "06" +# yyyy - Four digit year. 2006 is "2006" +# year - Four digit year. 2006 is "2006" + + +# -------------------------------------------------------------------------- +# +# Cut and paste the lines below to change the order in which your files +# appear on the menu. Don't worry about adding or removing files, Natural +# Docs will take care of that. +# +# You can further organize the menu by grouping the entries. Add a +# "Group: [name] {" line to start a group, and add a "}" to end it. +# +# You can add text and web links to the menu by adding "Text: [text]" and +# "Link: [name] ([URL])" lines, respectively. +# +# The formatting and comments are auto-generated, so don't worry about +# neatness when editing the file. Natural Docs will clean it up the next +# time it is run. When working with groups, just deal with the braces and +# forget about the indentation and comments. +# +# -------------------------------------------------------------------------- + + +Group: Kernel { + + File: head.s (kernel/head.s) + File: idt.s (kernel/idt.s) + File: multiboot.inc (kernel/multiboot.inc) + File: pic.s (kernel/pic.s) + File: setup_paging (kernel/paging.s) + + Group: Driver { + + File: serial.s (no auto-title, kernel/drivers/serial.s) + } # Group: Driver + + } # Group: Kernel + +Group: Lib { + + File: base.inc (lib/base.inc) + } # Group: Lib + +Group: Index { + + Index: Everything + Class Index: Classes + Constant Index: Constants + File Index: Files + Function Index: Functions + Macro Index: Macros + Type Index: Types + Variable Index: Variables + } # Group: Index + diff --git a/kernel/drivers/serial.s b/kernel/drivers/serial.s index 6d808c6..2aa194a 100644 --- a/kernel/drivers/serial.s +++ b/kernel/drivers/serial.s @@ -27,6 +27,14 @@ DLH equ 0x0 in al, dx %endmacro + ; Function: serial_init + ; + ; in: + ; none + ; + ; out: + ; none + ; global serial_init serial_init: COM_OUT COM1, IER, 0x00 @@ -38,6 +46,14 @@ serial_init: ret + ; Function: serial_write + ; + ; in: + ; none + ; + ; out: + ; none + ; global serial_write serial_write: push ebp diff --git a/kernel/head.s b/kernel/head.s index 5895d82..0260fa2 100644 --- a/kernel/head.s +++ b/kernel/head.s @@ -1,3 +1,5 @@ +; file: head.s +; [BITS 32] %include "base.inc" @@ -21,6 +23,16 @@ stack_bottom: stack_top: section .text + + ; Function: entry + ; + ; in: + ; EAX - Multiboot magic + ; EBX - Multiboot structure + ; + ; out: + ; none + ; global entry entry: mov esp, stack_top diff --git a/kernel/idt.s b/kernel/idt.s index a1ec1d0..8e121d6 100644 --- a/kernel/idt.s +++ b/kernel/idt.s @@ -1,3 +1,5 @@ +; file: idt.s +; [BITS 32] section .text global setup_idt @@ -29,9 +31,10 @@ extern isr %+ i section .data align 8 idt_ptr: - dw 255 * 8 + dw idt_entries.end-idt_entries-1 dd idt_entries +; variable: idt_entries align 8 idt_entries: times 256 dd 0x00000000, 0x00000000 diff --git a/kernel/isr.s b/kernel/isr.s index f512a49..3e5b796 100644 --- a/kernel/isr.s +++ b/kernel/isr.s @@ -5,20 +5,50 @@ %macro ISR_NO_ERR 1 global isr%1 isr%1: - cli - push byte 0 - push byte %1 + xchg bx, bx + push dword 0 + push dword %1 jmp isr_handler %endmacro %macro ISR_ERR 1 global isr%1 isr%1: - cli - push byte %1 + xchg bx, bx + push dword 1 + 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 + section .text ISR_NO_ERR 0 @@ -54,36 +84,47 @@ ISR_NO_ERR 29 ISR_NO_ERR 30 ISR_NO_ERR 31 +panic: + LOG msg_interrupt + htl + jmp panic + global isr_handler isr_handler: + push ds + push es + push fs + push gs + mov edi, 0x11111111 + mov eax, 0xAAAAAAAA pusha - mov ax, ds - push eax - mov ax, 0x10 + mov ax, 0x10 ; data segment mov ds, ax mov es, ax mov fs, ax mov gs, ax - LOG msg_interrupt - - extern pic_eoi - call pic_eoi - - pop eax - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax + call panic + ;extern pic_eoi + ;call pic_eoi + popa - add esp, 8 + pop gs + pop fs + pop es + pop ds + add esp, 8 ; int no & error code - sti iret section .rodata -msg_interrupt db "interrupt", 0 +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 + db "gs: %x fs: %x es: %x ds: %x", 0xA + db "int: %x err: %x eip: %x cs: %x", 0xA + db "flg: %x usp: %x ss: %x", 0x0 file db __FILE__, 0 diff --git a/kernel/multiboot.inc b/kernel/multiboot.inc index 620d735..1bab118 100644 --- a/kernel/multiboot.inc +++ b/kernel/multiboot.inc @@ -1,3 +1,5 @@ +; file: multiboot.inc + struc mb_info .flags: resd 1 diff --git a/kernel/paging.s b/kernel/paging.s index 3213e6c..97ea017 100644 --- a/kernel/paging.s +++ b/kernel/paging.s @@ -14,13 +14,21 @@ page_directory: section .text + ; Function: setup_paging + ; + ; in: + ; none + ; + ; out: + ; none + ; global setup_paging setup_paging: mov eax, page_directory mov cr3, eax mov eax, cr0 - or eax, 0x80000001 + or eax, 1 << 31 ; enable paging mov cr0, eax ret diff --git a/kernel/pic.s b/kernel/pic.s index 8c70f31..fcafb82 100644 --- a/kernel/pic.s +++ b/kernel/pic.s @@ -7,6 +7,14 @@ PIC2_DATA equ 0xA1 section .text + ; Function: setup_pic + ; + ; in: + ; none + ; + ; out: + ; none + ; global setup_pic setup_pic: mov al, 0x11 @@ -29,6 +37,14 @@ setup_pic: out PIC2_DATA, al ret + ; Function: pic_eoi + ; + ; in: + ; none + ; + ; out: + ; none + ; global pic_eoi pic_eoi: mov al, 0x20 diff --git a/kernel/pmm.s b/kernel/pmm.s index 98c6920..2ba46c3 100644 --- a/kernel/pmm.s +++ b/kernel/pmm.s @@ -164,8 +164,8 @@ setup_pmm_mmap: ;; TODO: mark as free in bitmap .third_pass: - push dword [edi + mb_mmap.addr] push dword [edi + mb_mmap.length] + push dword [edi + mb_mmap.addr] call bitmap_mark_range_free add esp, 8 jmp .next @@ -338,19 +338,27 @@ setup_pmm: leave ret -global alloc_frame -alloc_frame: +global alloc_frames +alloc_frames: push esp mov ebp, esp - + push edi + push esi + + mov edi, [ebp + 8] ; count + + pop esi + pop edi leave ret -global free_frame -free_frame: +global free_frames +free_frames: push esp mov ebp, esp + call bitmap_mark_range_free + leave ret diff --git a/lib/base.inc b/lib/base.inc index ca61406..a2166da 100644 --- a/lib/base.inc +++ b/lib/base.inc @@ -1,5 +1,7 @@ +; file: base.inc extern log_impl +; macro: LOG %macro LOG 1-* %rep %0 %rotate -1 diff --git a/lib/build.mk b/lib/build.mk index 8ef4299..ff732f3 100644 --- a/lib/build.mk +++ b/lib/build.mk @@ -21,4 +21,4 @@ include lib/*/build.mk $(foreach lib, $(LIBS), $(eval $(call LIBS_TEMPLATE,$(lib)))) lib/%.o: lib/%.s - $(AS) $(ASFLAGS) -o $@ $< + $(AS) -felf $(ASFLAGS) -o $@ $<