diff --git a/Makefile b/Makefile index de222bc..63890b4 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ .EXPORT_ALL_VARIABLES: +MAKEFLAGS += --no-print-directory + TOPDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) SYSROOTDIR := $(TOPDIR)/sysroot TOOLSDIR := $(TOPDIR)/tools @@ -30,7 +32,7 @@ QEMU_COMMON = \ -serial stdio \ -monitor telnet::4545,server,nowait \ -net nic,model=ne2k_isa \ - -machine isapc + -machine isapc SUBDIRS := external tools include boot kernel modules lib bin diff --git a/boot/intro.txt b/boot/intro.txt index 48cb259..8b11f91 100644 --- a/boot/intro.txt +++ b/boot/intro.txt @@ -12,7 +12,7 @@ Section: Legacy > +------------+ +-------------+ +--------------+ > -About: Memory Map +About: Real Mode Memory Map > > 0x100000 +-----------------------+ diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index ead28b6..daeaf7a 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -214,6 +214,9 @@ szMsgErrorNotFound db "ERROR: kernel not found", 0 ; ========================================================================= ; protected mode code ; ========================================================================= + + ;; subroutine: multiboot + ;; This subroutine handle multiboot structures and convert them to multiboot: ; https://www.gnu.org/software/grub/manual/multiboot/multiboot.html#Machine-state @@ -223,7 +226,8 @@ multiboot: ; get kernel from module - + ;; subroutine: common32 + ;; This subroutine move kernel to 0x100000 and setup temporary pagging then jump to kernel code. common32: mov [0xB8000], dword 0x07690748 @@ -242,15 +246,31 @@ common32: or edx, (PTE_P or PTE_W) mov [edi], edx add edi, 4 - add esi, 4096 + add esi, PAGE_SIZE inc ecx cmp ecx, 1024 jb @b - + + ; map 4mb right after kernel (for now we assume there is enough memory) + mov edi, boot_kernel_paging_table + xor ecx, ecx +@@: + mov edx, esi + or edx, (PTE_P or PTE_W) + mov [edi], edx + add edi, 4 + add esi, PAGE_SIZE + inc ecx + cmp ecx, 1024 + jb @b + + ; add entries to page directory mov dword [boot_page_directory], boot_0_page_table + (PDE_P or PDE_W) ; present and writable mov dword [boot_page_directory + (768 * 4)], boot_0_page_table + (PDE_P or PDE_W) + mov dword [boot_page_directory + (769 * 4)], boot_kernel_paging_table + (PDE_P or PDE_W) + mov eax, boot_page_directory mov cr3, eax @@ -278,7 +298,12 @@ inode_cache rb sizeof.Inode boot_page_directory: rb 4096 + ; we asume kernel is less than 4mb boot_0_page_table: rb 4096 + ; We map 4mb after kernel for future kernel page table/directory +boot_kernel_paging_table: + rb 4096 + _end: diff --git a/docs/config/Comments.txt b/docs/config/Comments.txt new file mode 100644 index 0000000..5df0345 --- /dev/null +++ b/docs/config/Comments.txt @@ -0,0 +1,90 @@ +Format: 2.3 + +# This is the Natural Docs comments file for this project. If you change +# anything here, it will apply to THIS PROJECT ONLY. You can edit the version +# in Natural Docs' Config folder to make the changes apply to all projects, +# but it's recommended that you edit this version instead. + + +# Ignored Keywords +# ------------------------------------------------------------------------ + +# If you'd like to prevent keywords from being recognized by Natural Docs, +# you can do it like this: +# +# Ignore Keywords: +# [keyword] +# [keyword] +# ... + + +# Comment Types +# ------------------------------------------------------------------------ +# The syntax reference is after the definitions. + +Alter Comment Type: Macro + + Keywords: + equ + + +# Each Natural Docs comment has a corresponding type which determine its +# behavior. You can define your own here or override the settings of the +# existing ones. +# +# Comment Type: [name] +# Alter Comment Type: [name] +# Creates a new comment type or changes an existing one. +# +# Display Name: [name] +# Plural Display Name: [name] +# The singular and plural name of the comment type as it should appear in +# the output. +# +# Simple Identifier: [name] +# The name of the comment type using only the letters A to Z. No spaces, +# numbers, symbols, or Unicode allowed. Defaults to the comment type name +# minus any unacceptable characters. This is used to generate things like +# CSS class names. +# +# Scope: [normal|start|end|always global] +# How the comment affects scope. Defaults to normal. +# normal - The comment stays within the current scope. +# start - The comment starts a new scope for all the comments +# beneath it, like class comments. +# end - The comment resets the scope back to global for all the +# comments beneath it, like section comments. +# always global - The comment is defined as a global symbol, but does not +# change the scope for any other comments. +# +# Flags: [flag], [flag], ... +# A combination of settings that apply to the comment type. +# Code, File, or Documentation +# Whether it's used to describe a code element, a file, or is a +# standalone documentation comment. Defaults to Code. +# Variable Type +# Whether it describes a code element that can be used as a variable's +# type. +# Class Hierarchy or Database Hierarchy +# Whether it describes a code element that should be included in the +# class or database hierarchy. Requires Scope: Start. +# Enum +# Whether it describes an enum. +# +# Keywords: +# [keyword] +# [keyword], [plural keyword] +# ... +# A list of the comment type's keywords. Each line after the heading is +# the keyword and optionally its plural form for list comments. You can +# reuse existing keywords to change their definition. When using +# "Alter Comment Type", these keywords are added to the existing ones +# rather than replacing them. +# +# [Language] Keywords: +# [keyword] +# [keyword], [plural keyword] +# ... +# A list of keywords that only apply to the comment type when using a +# specific programming language. Each line after the heading is the +# keyword and optionally its plural form for list comments. diff --git a/docs/config/Menu.txt b/docs/config/Menu.txt index 49a410c..87f4b0f 100644 --- a/docs/config/Menu.txt +++ b/docs/config/Menu.txt @@ -20,7 +20,7 @@ Timestamp: Updated yyyy/mm/dd # These are indexes you deleted, so Natural Docs will not add them again # unless you remove them from this line. -Don't Index: Variables, Macros, Classes +Don't Index: Macros, Classes, Variables # -------------------------------------------------------------------------- @@ -139,8 +139,11 @@ Group: Kernel { Group: Memory Manager { - File: mm.inc (kernel/mm/mm.inc) - File: pmm.inc (kernel/mm/pmm.inc) + File: bootstrap.inc (kernel/mm/bootstrap.inc) + File: Introduction (kernel/mm/intro.txt) + File: mm.inc (kernel/mm/mm.old.inc) + File: pmm.inc (kernel/mm/pmm.old.inc) + File: PMMFreeRange (kernel/mm/pmm.new.inc) } # Group: Memory Manager File: lock.inc (kernel/lock.inc) diff --git a/docs/config/Project.txt b/docs/config/Project.txt new file mode 100644 index 0000000..271d86d --- /dev/null +++ b/docs/config/Project.txt @@ -0,0 +1,215 @@ +Format: 2.3 + +# This is the main file you use to configure Natural Docs for your project. + + +# Project Information +# ------------------------------------------------------------------------ + +Title: StupidOS +Subtitle: 32-bit Operating System written in x86 assembly. + +Copyright: Copyright © 2024 d0p1 + +Timestamp: Updated yyyy/mm/dd +# m - Single digit month, when possible. January is "1". +# mm - Always double digit month. January is "01". +# mon - Short month word. January is "Jan". +# month - Long month word. January is "January". +# d - Single digit day, when possible. 1 is "1". +# dd - Always double digit day. 1 is "01". +# day - Day with text extension. 1 is "1st". +# yy - Double digit year. 2022 is "22". +# yyyy - Four digit year. 2022 is "2022". +# year - Four digit year. 2022 is "2022". + + +# This is where you put general information about your project. None of these +# settings are required, though Title is recommended. +# +# Title: [text] +# The name of your project. (R) and (TM) will be converted to their +# respective symbols. +# +# Subtitle: [text] +# A subtitle for your project, if desired. +# +# Copyright: [text] +# The copyright notice for your project. (C) will be converted to the +# copyright symbol. +# +# Timestamp: [text] +# Text explaining when the documentation was generated, such as "Last +# Updated Month Day Year", if you want that to be included. The following +# substitutions are performed: +# +# m - Single digit month, when possible. January is "1". +# mm - Always double digit month. January is "01". +# mon - Short month word. January is "Jan". +# month - Long month word. January is "January". +# d - Single digit day, when possible. 1 is "1". +# dd - Always double digit day. 1 is "01". +# day - Day with text extension. 1 is "1st". +# yy - Double digit year. 2022 is "22". +# yyyy - Four digit year. 2022 is "2022". +# year - Four digit year. 2022 is "2022". +# +# Style: [style] +# A custom style to apply to the generated documentation. See +# https://naturaldocs.org/reference/styles for more information. +# +# Home Page: [file] +# A custom home page for the generated documentation. It could be a +# documented file in one of the source folders or a HTML file in any +# location. +# +# Encoding: [name or code page number] +# Encoding: [name or code page number] *.[extension] +# The character encoding source files use if it is something other than +# Unicode. It can be specified as a name such as "iso-8859-1" or a code +# page number such as "28591". You can see the list of encodings your +# system supports by running Natural Docs with the --list-encodings command +# line option. +# +# Natural Docs defaults to Unicode which will handle all forms of UTF-8, +# UTF-16, and UTF-32. You can set a new default for all files or you can +# limit it to an extension such as "*.txt". You can use multiple Encoding +# lines to cover all the extensions that need them. +# +# You can also set encodings for specific folders by adding Encoding lines +# in Source Folder sections. + + +# Source Code +# ------------------------------------------------------------------------ + +Source Folder: ..\.. + Name: StupidOS + + +# This is where you tell Natural Docs which folders it should scan for source +# files. If you add any on the command line this section is ignored except +# for the properties of the ones from the command line. +# +# Source Folder: [folder] +# Specifies a folder which will be searched for source files. The path is +# relative to the project configuration folder, which lets this file remain +# portable across computers and not cause problems in version control +# systems. You can enter an absolute path and it will be converted +# automatically. +# +# Additional properties can be added after each source folder: +# +# Name: [name] +# How this source folder will appear in the menu if you have more than +# one. +# +# Encoding: [name or code page number] +# Encoding: [name or code page number] *.[extension] +# Encoding: [name or code page number] [folder] +# Encoding: [name or code page number] [folder]\*.[extension] +# The character encoding source files use if it's something other than +# Unicode. It can be specified as a name such as "iso-8859-1" or a code +# page number such as "28591". You can see the list of encodings your +# system supports by running Natural Docs with the --list-encodings +# command line option. +# +# Natural Docs defaults to Unicode which will handle all forms of UTF-8, +# UTF-16, and UTF-32. You can set a new default for all files in this +# folder, limit it to an extension such as "*.txt", limit it to a +# subfolder, or limit it to extensions in a subfolder. You can use +# multiple Encoding lines to cover all the subfolders and extensions +# that need them. + + +# Source Filtering +# ------------------------------------------------------------------------ + +Ignore Source Folder: ..\..\sysroot + + +# If there are any subfolders in the source code that you would like Natural +# Docs to ignore they can be added here. If you use any of these options on +# the command line this section is ignored. +# +# Ignore Source Folder: [folder] +# Tells Natural Docs to skip this folder when scanning files. +# +# Ignore Source Folder Pattern: [pattern] +# Tells Natural Docs to skip all folder names which match this pattern when +# scanning files. ? matches a single character, * matches zero or more +# characters. It applies to the entire folder name, so "cli" will not +# match "client", although "cli*" will. +# +# The data folders of common version control systems (.git, .svn, .cvs, .hg) +# are ignored automatically. You don't have to add them here. + + +# Images +# ------------------------------------------------------------------------ + +Image Folder: ..\img + + +# This is where you tell Natural Docs which folders it should look for images +# in. When you put something like (see diagram.jpg) in a comment Natural Docs +# will look for it relative to the source file it appears in plus any folders +# added here. If you add any on the command line this section is ignored. +# +# Image Folder: [folder] +# Specifies a folder which will be searched for image files. The path is +# relative to the project configuration folder, which lets this file remain +# portable across computers and not cause problems in version control +# systems. You can enter absolute paths and they will be converted +# automatically. + + + +# Generated Documentation +# ------------------------------------------------------------------------ + +HTML Output Folder: ..\html + + +# This is where you tell Natural Docs what kind of documentation you want +# built and where it should be put. If you use any of these options on the +# command line this section is ignored except for the properties of the ones +# from the command line. +# +# HTML Output Folder: [folder] +# Generates HTML documentation in the specified folder. The path is +# relative to the project configuration folder, which lets this file remain +# portable across computers and not cause problems in version control +# systems. You can enter an absolute path and it will be converted +# automatically. +# +# Additional properties can be added after each output folder: +# +# Title: [text] +# Subtitle: [text] +# Copyright: [text] +# Timestamp: [text] +# Style: [style] +# Home Page: [file] +# These properties can be overridden for just this output folder, which +# allows you to have multiple output folders with different styles or +# titles. See the Project Information section for descriptions of them. + + +# Global Settings +# ------------------------------------------------------------------------ + +# Other settings that apply to your entire project. Settings specified on the +# command line override the settings here. +# +# Tab Width: [width] +# The number of spaces tabs should be expanded to. +# +# Documented Only: [yes|no] +# Whether only documented code elements should appear in the output. +# Defaults to no. +# +# Auto Group: [yes|no] +# Whether groups should automatically apply to you code. Defaults to yes. + + diff --git a/docs/img/favicon.ico b/docs/img/favicon.ico index bcf8448..5df6435 100644 Binary files a/docs/img/favicon.ico and b/docs/img/favicon.ico differ diff --git a/docs/img/logo.png b/docs/img/logo.png index a8df1cb..f94a4be 100644 Binary files a/docs/img/logo.png and b/docs/img/logo.png differ diff --git a/docs/img/logo_3d.png b/docs/img/logo_3d.png index 61376ec..2130701 100644 Binary files a/docs/img/logo_3d.png and b/docs/img/logo_3d.png differ diff --git a/kernel/Makefile b/kernel/Makefile index 0f4ad01..3b061d6 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -15,8 +15,8 @@ KERNEL = vmstupid.sys SRCS = kernel.asm \ const.inc \ klog.inc \ - mm/mm.inc \ - mm/pmm.inc \ + mm/mm.old.inc \ + mm/pmm.old.inc \ lock.inc \ gdt.inc \ isr.inc \ diff --git a/kernel/kernel.asm b/kernel/kernel.asm index 79694cf..771a54b 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -117,7 +117,7 @@ kmain: include 'klog.inc' include 'dev/console.inc' include 'dev/dev.inc' - include 'mm/mm.inc' + include 'mm/mm.old.inc' include 'lock.inc' include 'gdt.inc' include 'syscall.inc' diff --git a/kernel/mm/bootstrap.inc b/kernel/mm/bootstrap.inc new file mode 100644 index 0000000..a581a5f --- /dev/null +++ b/kernel/mm/bootstrap.inc @@ -0,0 +1,7 @@ + ;; File: bootstrap.inc + ;; Bootstrap whole PMM and MM + + ;; Function: mm_bootstrap + ;; Setup recursive page dir at 0xFFFFF000 and temporary identity map first 3GB +mm_bootstrap: + ret diff --git a/kernel/mm/intro.txt b/kernel/mm/intro.txt new file mode 100644 index 0000000..31afe3f --- /dev/null +++ b/kernel/mm/intro.txt @@ -0,0 +1,2 @@ +File: Introduction + diff --git a/kernel/mm/mm.inc b/kernel/mm/mm.old.inc similarity index 99% rename from kernel/mm/mm.inc rename to kernel/mm/mm.old.inc index 25c5463..22151bb 100644 --- a/kernel/mm/mm.inc +++ b/kernel/mm/mm.old.inc @@ -27,7 +27,7 @@ ;; > 0x00000000 +---------------+ ;; -include "pmm.inc" +include "pmm.old.inc" include "../sys/mmu.inc" ;; Macro: KV2P diff --git a/kernel/mm/pmm.new.inc b/kernel/mm/pmm.new.inc new file mode 100644 index 0000000..deb771a --- /dev/null +++ b/kernel/mm/pmm.new.inc @@ -0,0 +1,7 @@ + ;; Struc: PMMFreeRange +struc PMMFreeRange { + .size dd ? + .next dd ? +} + +pPMMFreeListHead dd 0 diff --git a/kernel/mm/pmm.inc b/kernel/mm/pmm.old.inc similarity index 100% rename from kernel/mm/pmm.inc rename to kernel/mm/pmm.old.inc diff --git a/kernel/sys/mmu.inc b/kernel/sys/mmu.inc index c330fca..d309f1a 100644 --- a/kernel/sys/mmu.inc +++ b/kernel/sys/mmu.inc @@ -68,3 +68,6 @@ PTE_A = 0x020 PTE_D = 0x040 PTE_PAT = 0x080 PTE_G = 0x100 + + ;; PAGE_SIZE: Page size (4Kib) +PAGE_SIZE = 4096 diff --git a/kernel/vfs.inc b/kernel/vfs.inc index 8629d25..848a89f 100644 --- a/kernel/vfs.inc +++ b/kernel/vfs.inc @@ -4,20 +4,30 @@ ;; - ;; + ;; Struc: VFS + ;; + ;; .name - Filesystem name + ;; .next - pointer to next VFS + ;; .ops - pointer to VFS function struc VFS { - .name dd ? - .next dd ? - .op dd ? + .name dd ? + .next dd ? + .ops_ptr dd ? } DEFN VFS + ;; Struc: Mount + ;; + ;; .next - address of next mount + ;; .ops_ptr - address of mount ops + ;; .vnodes - struc Mount { - .next dd ? - .op dd ? - .vnodes dd ? - .flag dd ? - .bsize dd ? - .data dd ? + .next dd ? + .ops_ptr dd ? + .vnodes dd ? + .flag dd ? + .bsize dd ? + .data dd ? } struc VFSOps { @@ -30,6 +40,9 @@ struc VFSOps { .vget dd ? } +macro VNODE_TYPE name,value { +VNODE_TYPE_#name equ value +} ;; Constants: vnode types ;; ;; VNODE_TYPE_NON - XXX @@ -40,14 +53,14 @@ struc VFSOps { ;; VNODE_TYPE_LNK - XXX ;; VNODE_TYPE_SOCK - XXX ;; VNODE_TYPE_BAD - XXX -VNODE_TYPE_NON = 0x0 -VNODE_TYPE_REG = 0x1 -VNODE_TYPE_DIR = 0x2 -VNODE_TYPE_BLK = 0x3 -VNODE_TYPE_CHR = 0x4 -VNODE_TYPE_LNK = 0x5 -VNODE_TYPE_SOCK = 0x6 -VNODE_TYPE_BAD = 0x7 +VNODE_TYPE NON, 0x0 +VNODE_TYPE REG, 0x1 +VNODE_TYPE DIR, 0x2 +VNODE_TYPE BLK, 0x3 +VNODE_TYPE CHR, 0x4 +VNODE_TYPE LNK, 0x5 +VNODE_TYPE SOCK, 0x6 +VNODE_TYPE BAD, 0x7 ;; Struc: VNode struc VNode { diff --git a/releasetools/efiimage.sh b/releasetools/efiimage.sh new file mode 100644 index 0000000..00732b3 --- /dev/null +++ b/releasetools/efiimage.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +set -e + +: "${IMG=stupidos_efi.img}" +: "${EFI_PART_SIZE=1000000}" # 1Mb + +if [ ! -f Makefile ] +then + exit 1 +fi + +. ./releasetools/image.defaults +. ./releasetools/image.functions + +DESTDIR=${BUILDDIR}/hd +export DESTDIR + +if [ -f "${IMG}" ] +then + rm -f "${IMG}" +fi + +mkdir -p "${BUILDDIR}" "${OBJ}" + +mkdir -p "${DESTDIR}/boot" + +create_stpdboot_ini "${DESTDIR}/boot" + +make + +echo "" +echo "Disk image at $(pwd)/${IMG}" diff --git a/releasetools/hdimage.sh b/releasetools/hdimage.sh index 7bc0178..58b6b7c 100755 --- a/releasetools/hdimage.sh +++ b/releasetools/hdimage.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -e -: "${IMG=disk.img}" +: "${IMG=stupidos_hd.img}" if [ ! -f Makefile ] then diff --git a/releasetools/image.functions b/releasetools/image.functions index 5585c59..0500472 100644 --- a/releasetools/image.functions +++ b/releasetools/image.functions @@ -35,6 +35,7 @@ get_grub() create_efi_image() { + echo } @@ -46,9 +47,13 @@ create_stpdboot_ini() stupid_ini="$(cat < "${target}/stupid.ini" } + +create_hd_image() +{ + +}