Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git b/ben_common.asm a/ben_common.asm
- old mode 100755
- new mode 100644
- index b12978d..58093c1
- --- b/ben_common.asm
- +++ a/ben_common.asm
- @@ -1,3 +1,19 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Load Kernel Args
- +; ------------------------------------------------------------------
- +
- SECTION .text
- USE16
- @@ -9,6 +25,10 @@ args:
- .env_base dq 0
- .env_size dq 0
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Load Kernel Args
- +; ------------------------------------------------------------------
- +
- startup:
- ; enable A20-Line via IO-Port 92, might not work on all motherboards
- in al, 0x92
- @@ -17,74 +37,119 @@ startup:
- %ifdef KERNEL
- mov edi, [args.kernel_base]
- - mov ecx, (kernel_file.end - kernel_file)
- + mov ecx, (benos_kernel_file.end - benos_kernel_file)
- mov [args.kernel_size], ecx
- - mov eax, (kernel_file - boot)/512
- + mov eax, (benos_kernel_file - boot)/512
- add ecx, 511
- shr ecx, 9
- call load_extent
- %else
- - call redoxfs
- + call benfs
- test eax, eax
- jnz error
- %endif
- - jmp .loaded_kernel
- + jmp .loaded_benos_kernel
- +
- +.loaded_benos_kernel:
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - benOS Memory Mapping Call
- +; ------------------------------------------------------------------
- -.loaded_kernel:
- - call memory_map
- + call ben_mm
- - call vesa
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - benOS BenPlay Video Loaders / Mode Finder
- +; ------------------------------------------------------------------
- +
- + call benplay
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Initialize FPU
- +; ------------------------------------------------------------------
- mov si, init_fpu_msg
- call print
- call initialize.fpu
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Initialize SSE
- +; ------------------------------------------------------------------
- +
- mov si, init_sse_msg
- call print
- call initialize.sse
- - mov si, startup_arch_msg
- + mov si, startup_ben_arch_msg
- call print
- - jmp startup_arch
- + jmp startup_ben_arch
- +
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders
- +; LOAD DISK 'EXTENT' INTO HIGH MEMORY
- +; EAX - Sector Address
- +; ECX - Sector Count
- +; EDI - Destination
- +; ------------------------------------------------------------------
- -# load a disk extent into high memory
- -# eax - sector address
- -# ecx - sector count
- -# edi - destination
- load_extent:
- - ; loading kernel to 1MiB
- - ; move part of kernel to startup_end via bootsector#load and then copy it up
- - ; repeat until all of the kernel is loaded
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders
- +; LOADING KERNEL TO 1 MEGABYTE
- +; MOVE PARTIAL PIECE OF BENOS MICROKERNEL TO BENOS_LAUNCH_END
- +; THEN - COPY IT UP
- +; THEN - REPEAT UNTIL ALL OF THE benOS MICROKERNEL HAS BEEN LOADED
- +; ------------------------------------------------------------------
- +
- buffer_size_sectors equ 127
- .lp:
- cmp ecx, buffer_size_sectors
- jb .break
- - ; saving counter
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Save Counter
- +; ------------------------------------------------------------------
- +
- push eax
- push ecx
- push edi
- - ; populating buffer
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Populate Buffer
- +; ------------------------------------------------------------------
- +
- mov ecx, buffer_size_sectors
- - mov bx, startup_end
- + mov bx, benos_launch_end
- mov dx, 0x0
- - ; load sectors
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Load Sector
- +; ------------------------------------------------------------------
- +
- call load
- - ; set up unreal mode
- - call unreal
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Setup benUnreal Mode
- +; ------------------------------------------------------------------
- +
- + call benur
- pop edi
- - ; move data
- - mov esi, startup_end
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Move Data To benOS Launch End Stage
- +; ------------------------------------------------------------------
- +
- + mov esi, benos_launch_end
- mov ecx, buffer_size_sectors * 512 / 4
- cld
- a32 rep movsd
- @@ -96,6 +161,11 @@ load_extent:
- sub ecx, buffer_size_sectors
- jmp .lp
- +
- +; ------------------------------------------------------------------------------------
- +; benOS Common Loaders - Any Left Over Microkernel Outside The Buffer - Loads Here
- +; ------------------------------------------------------------------------------------
- +
- .break:
- ; load the part of the kernel that does not fill the buffer completely
- test ecx, ecx
- @@ -104,38 +174,61 @@ load_extent:
- push ecx
- push edi
- - mov bx, startup_end
- + mov bx, benos_launch_end
- mov dx, 0x0
- call load
- - ; moving remnants of kernel
- - call unreal
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Moving Remnants Of Microkernel
- +; ------------------------------------------------------------------
- +
- + call benur
- pop edi
- pop ecx
- - mov esi, startup_end
- + mov esi, benos_launch_end
- shl ecx, 7 ; * 512 / 4
- cld
- a32 rep movsd
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Finalization Of Common Bootloader Stage
- +; ------------------------------------------------------------------
- +
- +
- .finish:
- call print_line
- ret
- -%include "config.asm"
- -%include "descriptor_flags.inc"
- -%include "gdt_entry.inc"
- -%include "unreal.asm"
- -%include "memory_map.asm"
- -%include "vesa.asm"
- -%include "initialize.asm"
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - Common Imports
- +; 'benconfig.asm' - benOS Bootloader Configuration
- +; 'ben_df.asm' - benOS Bootloader Diffs
- +; 'global_descriptor_table_entry.inc' - benOS GDTE
- +; 'benur.asm' - benOS Bootloader BENUR Mode
- +; 'ben_mm.asm' - benOS Bootloader Memory Mapping
- +; 'benplay.asm' - benOS BenPlay Bootloader Video Config / Driver Loader
- +; 'startup_ben.asm' - benOS Bootloader Launcher
- +; 'benfs.asm' - benOS Local FileSystem
- +; ------------------------------------------------------------------
- +
- +%include "benconfig.asm"
- +%include "ben_df.inc"
- +%include "global_descriptor_table_entry.inc"
- +%include "benur.asm"
- +%include "ben_mm.asm"
- +%include "benplay.asm"
- +%include "startup_ben.asm"
- %ifndef KERNEL
- - %include "redoxfs.asm"
- + %include "benfs.asm"
- %endif
- -init_fpu_msg: db "Init FPU",13,10,0
- -init_sse_msg: db "Init SSE",13,10,0
- -init_pit_msg: db "Init PIT",13,10,0
- -init_pic_msg: db "Init PIC",13,10,0
- -startup_arch_msg: db "Startup Arch",13,10,0
- +init_fpu_msg: db "Initialize FPU",13,10,0
- +init_sse_msg: db "Initialize SSE",13,10,0
- +init_pit_msg: db "Initialize PIT",13,10,0
- +init_pic_msg: db "Initialize PIC",13,10,0
- +startup_ben_arch_msg: db "Startup benOS Arch",13,10,0
- diff --git b/ben_df.inc a/ben_df.inc
- old mode 100755
- new mode 100644
- index 210c98d..83bd186
- --- b/ben_df.inc
- +++ a/ben_df.inc
- @@ -1,3 +1,19 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS Common Loaders - DF Loader / Configuration
- +; ------------------------------------------------------------------
- +
- attrib:
- .present equ 1 << 7
- .ring1 equ 1 << 5
- diff --git b/ben_mm.asm a/ben_mm.asm
- old mode 100755
- new mode 100644
- index a5cdc70..4d5c30c
- --- b/ben_mm.asm
- +++ a/ben_mm.asm
- @@ -1,32 +1,65 @@
- -SECTION .text
- -USE16
- -;Generate a memory map at 0x500 to 0x5000 (available memory not used for kernel or bootloader)
- -memory_map:
- -.start equ 0x0500
- -.end equ 0x5000
- -.length equ .end - .start
- -
- - xor eax, eax
- - mov di, .start
- - mov ecx, .length / 4 ; moving 4 Bytes at once
- - cld
- - rep stosd
- -
- - mov di, .start
- - mov edx, 0x534D4150
- - xor ebx, ebx
- -.lp:
- - mov eax, 0xE820
- - mov ecx, 24
- -
- - int 0x15
- - jc .done ; Error or finished
- -
- - cmp ebx, 0
- - je .done ; Finished
- -
- - add di, 24
- - cmp di, .end
- - jb .lp ; Still have buffer space
- -.done:
- - ret
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS Bootloader - Memory Mapping
- +; ------------------------------------------------------------------
- +
- +SECTION .text
- +USE16
- +
- +; ------------------------------------------------------------------
- +; benOS Bootloader - At 0x500 to 0x5000 We Generate A Memory Map
- +; /// BenchX Desktop will pull from available memory that hasn't been used.
- +; /// At this boot stage the benOS microkernel and bootloader are already utilizing
- +; memory from your BenchX Desktop, to startup benOS.
- +; ------------------------------------------------------------------
- +
- +ben_mm:
- +.start equ 0x0500
- +.end equ 0x5000
- +.length equ .end - .start
- +
- + xor eax, eax
- + mov di, .start
- + mov ecx, .length / 4 ; moving 4 Bytes at once
- + cld
- + rep stosd
- +
- + mov di, .start
- + mov edx, 0x534D4150 ; Set EDX to the magic number 0x534D4150.
- + xor ebx, ebx
- +
- +; ------------------------------------------------------------------
- +; benOS Bootloader - Memory Mapping Loop
- +; ------------------------------------------------------------------
- +
- +.lp:
- + mov eax, 0xE820
- + mov ecx, 24
- +
- + int 0x15
- + jc .done ; MM Loop either errors out or finishes.
- +
- + cmp ebx, 0
- + je .done ; MM Loop finalizes its boot stage loop process.
- +
- + add di, 24
- + cmp di, .end
- + jb .lp ; MM Loop has buffer space available and left over.
- +
- +; ----------------------------------------------------------------------
- +; benOS Bootloader - Memory Mapping Complete, Returns Map > Next Stage
- +; ----------------------------------------------------------------------
- +
- +.done:
- + ret
- diff --git b/benconfig.asm a/benconfig.asm
- old mode 100755
- new mode 100644
- index 8e3b220..86cb23d
- --- b/benconfig.asm
- +++ a/benconfig.asm
- @@ -1,17 +1,41 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Configuration Stage
- +; ------------------------------------------------------------------
- +
- SECTION .text
- USE16
- align 512, db 0
- -config:
- +; ------------------------------------------------------------------
- +; benOS Boot Process - BenConfig Initializer
- +; ------------------------------------------------------------------
- +
- +benconfig:
- .xres: dw 0
- .yres: dw 0
- -times 512 - ($ - config) db 0
- +times 512 - ($ - benconfig) db 0
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Save BenConfig
- +; ------------------------------------------------------------------
- -save_config:
- - mov eax, (config - boot) / 512
- - mov bx, config
- +save_benconfig:
- + mov eax, (benconfig - boot) / 512
- + mov bx, benconfig
- mov cx, 1
- xor dx, dx
- call store
- diff --git b/benfs.asm a/benfs.asm
- old mode 100755
- new mode 100644
- index 4264b46..0644ce6
- --- b/benfs.asm
- +++ a/benfs.asm
- @@ -1,12 +1,32 @@
- -%define BLOCK_SHIFT 12
- -%define BLOCK_SIZE (1 << BLOCK_SHIFT)
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +%define X_BLOCK_SHIFT 12
- +%define X_BLOCK_SIZE (1 << X_BLOCK_SHIFT)
- +
- +; ------------------------------------------------------------------
- +; benOS Initial Extent Structure For Block Data
- +; ------------------------------------------------------------------
- struc Extent
- .block: resq 1,
- .length: resq 1
- endstruc
- -struc Node
- +; ------------------------------------------------------------------
- +; benOS Initial BenUnit Structure
- +; ------------------------------------------------------------------
- +
- +struc BenUnit
- .mode: resw 1
- .uid: resd 1
- .gid: resd 1
- @@ -17,192 +37,278 @@ struc Node
- .name: resb 222
- .parent: resq 1
- .next: resq 1
- - .extents: resb (BLOCK_SIZE - 272)
- + .extents: resb (X_BLOCK_SIZE - 272)
- endstruc
- -struc Header
- - ; Signature, should be b"RedoxFS\0"
- - .signature: resb 8
- - ; Version, should be 2
- - .version: resq 1,
- - ; Disk ID, a 128-bit unique identifier
- - .uuid: resb 16,
- - ; Disk size, in BLOCK_SIZE-byte sectors
- +; ------------------------------------------------------------------
- +; benOS Initial BenHeader Structure For Data Block Header
- +; ------------------------------------------------------------------
- +
- +struc BenHeader
- + ; benFS Signature
- + ; This should be b"benFS\0". If not, there are major bootloader errors. << IMPORTANT
- + .ben_signature: resb 8
- + ; benFS BenHeader Version
- + .ben_version: resq 1,
- + ; BenchDisk ID, a 128-bit BenchX on-board disk UID
- + .benx_uuid: resb 16,
- + ; BenchDisk size
- .size: resq 1,
- - ; Block of root node
- + ; Block of root benOS benunit within the stack
- .root: resq 1,
- - ; Block of free space node
- + ; Block of free space benOS benunit
- .free: resq 1
- - ; Padding
- - .padding: resb (BLOCK_SIZE - 56)
- + ; benFS BenHeader Padding
- + .padding: resb (X_BLOCK_SIZE - 56)
- endstruc
- -redoxfs:
- - call redoxfs.open
- +; ------------------------------------------------------------------
- +; benOS Load benFS along with initial BenHeader
- +; ------------------------------------------------------------------
- +
- +benfs:
- + call benfs.open
- test eax, eax
- - jz .good_header
- + jz .ben_header
- ret
- - .good_header:
- - mov eax, [.header + Header.root]
- - mov bx, .dir
- - call .node
- +; ------------------------------------------------------------------
- +; benOS Load Full BenHeader
- +; ------------------------------------------------------------------
- +
- + .ben_header:
- + mov eax, [.ben_header + BenHeader.root]
- + mov bx, .ben_dir
- + call .benunit
- - jmp redoxfs.root
- + jmp benfs.root
- - ; node in eax, buffer in bx
- - .node:
- - shl eax, (BLOCK_SHIFT - 9)
- - add eax, (filesystem - boot)/512
- - mov cx, (BLOCK_SIZE/512)
- +; ------------------------------------------------------------------
- +; benOS Load BenUnit (Load Disk and benOS FileSystem)
- +; ------------------------------------------------------------------
- +
- + .benunit:
- + shl eax, (X_BLOCK_SHIFT - 9)
- + add eax, (benos_filesystem - boot)/512
- + mov cx, (X_BLOCK_SIZE/512)
- mov dx, 0
- call load
- call print_line
- ret
- - align BLOCK_SIZE, db 0
- + align X_BLOCK_SIZE, db 0
- +
- +; ------------------------------------------------------------------
- +; benOS Load BenHeader
- +; ------------------------------------------------------------------
- - .header:
- - times BLOCK_SIZE db 0
- + .ben_header:
- + times X_BLOCK_SIZE db 0
- - .dir:
- - times BLOCK_SIZE db 0
- +; ------------------------------------------------------------------
- +; benOS Load BenDir
- +; ------------------------------------------------------------------
- - .file:
- - times BLOCK_SIZE db 0
- + .ben_dir:
- + times X_BLOCK_SIZE db 0
- - .env:
- - db "REDOXFS_UUID="
- - .env.uuid:
- +; ------------------------------------------------------------------
- +; benOS Load BenFile
- +; ------------------------------------------------------------------
- +
- + .ben_file:
- + times X_BLOCK_SIZE db 0
- +
- + .ben_env:
- + db "BENOSFS_BENX_UUID="
- + .ben_env.uuid:
- db "00000000-0000-0000-0000-000000000000"
- - .env.end:
- + .ben_env.end:
- db 0
- -redoxfs.open:
- +; ------------------------------------------------------------------
- +; benOS Open benFS Local File System
- +; ------------------------------------------------------------------
- +
- +benfs.open:
- mov eax, 0
- - mov bx, redoxfs.header
- - call redoxfs.node
- + mov bx, benfs.ben_header
- + call benfs.benunit
- mov bx, 0
- - .sig:
- - mov al, [redoxfs.header + Header.signature + bx]
- - mov ah, [.signature + bx]
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS Signature
- +; ------------------------------------------------------------------
- +
- + .ben_sig:
- + mov al, [benfs.ben_header + BenHeader.ben_signature + bx]
- + mov ah, [.ben_signature + bx]
- cmp al, ah
- - jne .sig_err
- + jne .ben_sig_err
- inc bx
- cmp bx, 8
- - jl .sig
- + jl .ben_sig
- mov bx, 0
- - .ver:
- - mov al, [redoxfs.header + Header.version + bx]
- - mov ah, [.version + bx]
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS Version
- +; ------------------------------------------------------------------
- +
- + .ben_ver:
- + mov al, [benfs.ben_header + BenHeader.ben_version + bx]
- + mov ah, [.ben_version + bx]
- cmp al, ah
- - jne .ver_err
- + jne .ben_ver_err
- inc bx
- - jl .ver
- + jl .ben_ver
- - lea si, [redoxfs.header + Header.signature]
- + lea si, [benfs.ben_header + BenHeader.signature]
- call print
- mov al, ' '
- call print_char
- - mov di, redoxfs.env.uuid
- + mov di, benfs.ben_env.benx_uuid
- xor si, si
- - .uuid:
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS (benX) UUID
- +; ------------------------------------------------------------------
- +
- + .benx_uuid:
- cmp si, 4
- - je .uuid.dash
- + je .benx_uuid.dash
- cmp si, 6
- - je .uuid.dash
- + je .benx_uuid.dash
- cmp si, 8
- - je .uuid.dash
- + je .benx_uuid.dash
- cmp si, 10
- - je .uuid.dash
- - jmp .uuid.no_dash
- - .uuid.dash:
- + je .benx_uuid.dash
- + jmp .benx_uuid.no_dash
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS (benX) UUID DASH, NODASH, CHAR and all below 0xA
- +; ------------------------------------------------------------------
- +
- + .benx_uuid.dash:
- mov al, '-'
- mov [di], al
- inc di
- - .uuid.no_dash:
- - mov bx, [redoxfs.header + Header.uuid + si]
- + .benx_uuid.no_dash:
- + mov bx, [benfs.ben_header + BenHeader.benx_uuid + si]
- rol bx, 8
- mov cx, 4
- - .uuid.char:
- + .benx_uuid.char:
- mov al, bh
- shr al, 4
- cmp al, 0xA
- - jb .uuid.below_0xA
- + jb .benx_uuid.below_0xA
- add al, 'a' - 0xA - '0'
- - .uuid.below_0xA:
- + .benx_uuid.below_0xA:
- add al, '0'
- mov [di], al
- inc di
- shl bx, 4
- - loop .uuid.char
- + loop .benx_uuid.char
- add si, 2
- cmp si, 16
- - jb .uuid
- + jb .benx_uuid
- - mov si, redoxfs.env.uuid
- + mov si, benfs.ben_env.benx_uuid
- call print
- call print_line
- xor ax, ax
- ret
- - .err_msg: db "Failed to open RedoxFS: ",0
- - .sig_err_msg: db "Signature error",13,10,0
- - .ver_err_msg: db "Version error",13,10,0
- +; ------------------------------------------------------------------
- +; benOS Load benFS Bootloader Error Messages
- +; ------------------------------------------------------------------
- +
- + .ben_err_msg: db "benOS bootloader failed to open benFS: ",0
- + .ben_sig_err_msg: db "benFS Signature error",13,10,0
- + .ben_ver_err_msg: db "benFS Version error",13,10,0
- - .sig_err:
- - mov si, .err_msg
- +; ------------------------------------------------------------------
- +; benOS Load benFS Signature Error
- +; ------------------------------------------------------------------
- +
- + .ben_sig_err:
- + mov si, .ben_err_msg
- call print
- - mov si, .sig_err_msg
- + mov si, .ben_sig_err_msg
- call print
- mov ax, 1
- ret
- - .ver_err:
- - mov si, .err_msg
- +; ------------------------------------------------------------------
- +; benOS Load benFS Version Error
- +; ------------------------------------------------------------------
- +
- + .ben_ver_err:
- + mov si, .ben_err_msg
- call print
- - mov si, .ver_err_msg
- + mov si, .ben_ver_err_msg
- call print
- mov ax, 1
- ret
- - .signature: db "RedoxFS",0
- - .version: dq 3
- +; ------------------------------------------------------------------
- +; benOS Load benFS Signature
- +; ------------------------------------------------------------------
- + .ben_signature: db "benFS",0
- -redoxfs.root:
- - lea si, [redoxfs.dir + Node.name]
- +; ------------------------------------------------------------------
- +; benOS Load benFS Version
- +; ------------------------------------------------------------------
- +
- + .ben_version: dq 3
- +
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS Root Local FileSystem
- +; ------------------------------------------------------------------
- +
- +benfs.root:
- + lea si, [benfs.ben_dir + BenUnit.name]
- call print
- call print_line
- +; ------------------------------------------------------------------
- +; benOS Load benFS Root Local FileSystem [LOOP]
- +; ------------------------------------------------------------------
- +
- .lp:
- mov bx, 0
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS Root Local FileSystem [EXTENTS]
- +; ------------------------------------------------------------------
- +
- .ext:
- - mov eax, [redoxfs.dir + Node.extents + bx + Extent.block]
- + mov eax, [benfs.ben_dir + BenUnit.extents + bx + Extent.block]
- test eax, eax
- jz .next
- - mov ecx, [redoxfs.dir + Node.extents + bx + Extent.length]
- + mov ecx, [benfs.ben_dir + BenUnit.extents + bx + Extent.length]
- test ecx, ecx
- jz .next
- - add ecx, BLOCK_SIZE
- + add ecx, X_BLOCK_SIZE
- dec ecx
- - shr ecx, BLOCK_SHIFT
- + shr ecx, X_BLOCK_SHIFT
- push bx
- @@ -210,12 +316,12 @@ redoxfs.root:
- push eax
- push ecx
- - mov bx, redoxfs.file
- - call redoxfs.node
- + mov bx, benfs.file
- + call benfs.benunit
- mov bx, 0
- .ext_sec_kernel:
- - mov al, [redoxfs.file + Node.name + bx]
- + mov al, [benfs.file + BenUnit.name + bx]
- mov ah, [.kernel_name + bx]
- cmp al, ah
- @@ -229,7 +335,7 @@ redoxfs.root:
- pop ecx
- pop eax
- pop bx
- - jmp redoxfs.kernel
- + jmp benfs.kernel
- .ext_sec_kernel_break:
- pop ecx
- @@ -242,18 +348,26 @@ redoxfs.root:
- pop bx
- add bx, Extent_size
- - cmp bx, (BLOCK_SIZE - 272)
- + cmp bx, (X_BLOCK_SIZE - 272)
- jb .ext
- +; ------------------------------------------------------------------
- +; benOS Load benFS Next BenUnit
- +; ------------------------------------------------------------------
- +
- .next:
- - mov eax, [redoxfs.dir + Node.next]
- + mov eax, [benfs.ben_dir + BenUnit.next]
- test eax, eax
- jz .no_kernel
- - mov bx, redoxfs.dir
- - call redoxfs.node
- + mov bx, benfs.ben_dir
- + call benfs.benunit
- jmp .lp
- +; ------------------------------------------------------------------
- +; benOS Load benFS - [IF NO KERNEL]
- +; ------------------------------------------------------------------
- +
- .no_kernel:
- mov si, .no_kernel_msg
- call print
- @@ -266,23 +380,42 @@ redoxfs.root:
- mov eax, 1
- ret
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS - Microkernel Information / No Kernel Error Message
- +; ------------------------------------------------------------------
- +
- .kernel_name: db "kernel",0
- - .no_kernel_msg: db "Did not find: ",0
- + .no_kernel_msg: db "benOS bootloader: Did not find ",0
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS - Load Microkernel
- +; ------------------------------------------------------------------
- -redoxfs.kernel:
- - lea si, [redoxfs.file + Node.name]
- +benfs.kernel:
- + lea si, [benfs.ben_file + BenUnit.name]
- call print
- call print_line
- mov edi, [args.kernel_base]
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS - Microkernel Loader [LOOP]
- +; ------------------------------------------------------------------
- +
- .lp:
- mov bx, 0
- +
- +; ------------------------------------------------------------------
- +; benOS Load benFS - Microkernel Loader [EXTENTS]
- +; ------------------------------------------------------------------
- +
- .ext:
- - mov eax, [redoxfs.file + Node.extents + bx + Extent.block]
- + mov eax, [benfs.ben_file + BenUnit.extents + bx + Extent.block]
- test eax, eax
- jz .next
- - mov ecx, [redoxfs.file + Node.extents + bx + Extent.length]
- + mov ecx, [benfs.ben_file + BenUnit.extents + bx + Extent.length]
- test ecx, ecx
- jz .next
- @@ -293,9 +426,9 @@ redoxfs.kernel:
- push edi
- - shl eax, (BLOCK_SHIFT - 9)
- - add eax, (filesystem - boot)/512
- - add ecx, BLOCK_SIZE
- + shl eax, (X_BLOCK_SHIFT - 9)
- + add eax, (benos_filesystem - boot)/512
- + add ecx, X_BLOCK_SIZE
- dec ecx
- shr ecx, 9
- call load_extent
- @@ -312,19 +445,27 @@ redoxfs.kernel:
- cmp bx, Extent_size * 16
- jb .ext
- +; ------------------------------------------------------------------
- +; benOS Load benFS - Load Next BenUnit
- +; ------------------------------------------------------------------
- +
- .next:
- - mov eax, [redoxfs.file + Node.next]
- + mov eax, [benfs.ben_file + BenUnit.next]
- test eax, eax
- jz .done
- push edi
- - mov bx, redoxfs.file
- - call redoxfs.node
- + mov bx, benfs.ben_file
- + call benfs.benunit
- pop edi
- jmp .lp
- +; ------------------------------------------------------------------
- +; benOS Load benFS - Finalizing Loading of benFS Local File System
- +; ------------------------------------------------------------------
- +
- .done:
- sub edi, [args.kernel_base]
- mov [args.kernel_size], edi
- diff --git b/benh_disk.asm a/benh_disk.asm
- old mode 100755
- new mode 100644
- index 1ef4cc3..fed8fbb
- --- b/benh_disk.asm
- +++ a/benh_disk.asm
- @@ -1,33 +1,72 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- sectalign off
- -%include "bootsector.asm"
- +%include "benstart.asm"
- +
- +; ------------------------------------------------------------------
- +; benOS Launch Start >> i386 or x86_64
- +; ------------------------------------------------------------------
- +
- +benos_launch_start:
- +
- +; ------------------------------------------------------------------
- +; benOS i386 Launch Loader
- +; ------------------------------------------------------------------
- -startup_start:
- %ifdef ARCH_i386
- - %include "startup-i386.asm"
- + %include "benos-i386.asm"
- %endif
- +; ------------------------------------------------------------------
- +; benOS x86_64 Launch Loader
- +; ------------------------------------------------------------------
- +
- %ifdef ARCH_x86_64
- - %include "startup-x86_64.asm"
- + %include "benos-x86_64.asm"
- %endif
- align 512, db 0
- -startup_end:
- +benos_launch_end:
- +
- +; ------------------------------------------------------------------
- +; benOS Microkernel Loader
- +; ------------------------------------------------------------------
- %ifdef KERNEL
- - kernel_file:
- + benos_kernel_file:
- %defstr KERNEL_STR %[KERNEL]
- incbin KERNEL_STR
- .end:
- align 512, db 0
- %else
- - align BLOCK_SIZE, db 0
- - %ifdef FILESYSTEM
- - filesystem:
- - %defstr FILESYSTEM_STR %[FILESYSTEM]
- - incbin FILESYSTEM_STR
- +
- +; ------------------------------------------------------------------
- +; benOS If Microkernel Has Already Loaded, Load FileSystem
- +; ------------------------------------------------------------------
- +
- + align X_BLOCK_SIZE, db 0
- + %ifdef BEN_FILESYSTEM
- + benos_filesystem:
- + %defstr BEN_FILESYSTEM_STR %[BEN_FILESYSTEM]
- + incbin BEN_FILESYSTEM_STR
- .end:
- - align BLOCK_SIZE, db 0
- + align X_BLOCK_SIZE, db 0
- +
- +; --------------------------------------------------------------------------------
- +; benOS If Microkernel and FileSystem Already Loaded, Execute Loaded Filesystem
- +; --------------------------------------------------------------------------------
- +
- %else
- - filesystem:
- + benos_filesystem:
- %endif
- %endif
- diff --git b/benos-x86_64.asm a/benos-x86_64.asm
- old mode 100755
- new mode 100644
- index 53dbf16..5b920cb
- --- b/benos-x86_64.asm
- +++ a/benos-x86_64.asm
- @@ -1,4 +1,30 @@
- -trampoline:
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; =================================================================================
- +; benOS Bootloader - BenBoot Stage
- +; =================================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS BenBoot Stage - Step By Step
- +; 1. Check Readiness of benOS Bootloader
- +; 2. Get CPU ID
- +; 3. Initialize Table
- +; 4. Start benOS Stack
- +; 5. Exit benOS Stack
- +; 6. Exit Code
- +; ------------------------------------------------------------------
- +
- +benboot:
- .ready: dq 0
- .cpu_id: dq 0
- .page_table: dq 0
- @@ -6,7 +32,11 @@ trampoline:
- .stack_end: dq 0
- .code: dq 0
- - times 512 - ($ - trampoline) db 0
- + times 512 - ($ - benboot) db 0
- +
- +; =================================================================================
- +; benOS Bootloader - 'startup_ap' - Initialize benOS Stack
- +; =================================================================================
- startup_ap:
- cli
- @@ -16,68 +46,119 @@ startup_ap:
- mov es, ax
- mov ss, ax
- - ; initialize stack
- +; ==================================================================
- +; benOS Bootloader - Initialize benOS Stack, FPU and SSE
- +; ==================================================================
- +
- mov sp, 0x7C00
- call initialize.fpu
- call initialize.sse
- - ;cr3 holds pointer to PML4
- +; ==================================================================
- +; benOS Bootloader - CR3 Point to PML4
- +; ==================================================================
- +
- mov edi, 0x70000
- mov cr3, edi
- - ;enable FXSAVE/FXRSTOR, Page Global, Page Address Extension, and Page Size Extension
- +
- +; =============================================================================
- +; benOS Bootloader - Enable FXSAVE/FXRSTOR/PG_GLOBAL/PG_ADDR_EXT/PG_SIZE_EXT
- +; =============================================================================
- +
- mov eax, cr4
- or eax, 1 << 9 | 1 << 7 | 1 << 5 | 1 << 4
- mov cr4, eax
- - ; load protected mode GDT
- +; ======================================================================
- +; benOS Bootloader - Load Global Descriptor Tables In Protected Mode
- +; ======================================================================
- +
- lgdt [gdtr]
- - mov ecx, 0xC0000080 ; Read from the EFER MSR.
- + mov ecx, 0xC0000080 ; Read via the Extended Feature Enable Register Model Specific Registers.
- rdmsr
- - or eax, 1 << 11 | 1 << 8 ; Set the Long-Mode-Enable and NXE bit.
- + or eax, 1 << 11 | 1 << 8 ; Enable Long-Mode-Enable and NXE bit for the USE64 Variable later.
- wrmsr
- - ;enabling paging and protection simultaneously
- +; ======================================================================
- +; benOS Bootloader - Enable Simulataneous Paging and Protection
- +; ======================================================================
- +
- mov ebx, cr0
- - or ebx, 1 << 31 | 1 << 16 | 1 ;Bit 31: Paging, Bit 16: write protect kernel, Bit 0: Protected Mode
- + or ebx, 1 << 31 | 1 << 16 | 1 ;Bit 31: benOS Paging, Bit 16: Write-Protected benOS Microkernel, Bit 0: Protected Mode
- mov cr0, ebx
- - ; far jump to enable Long Mode and load CS with 64 bit segment
- +; ================================================================================================
- +; benOS Bootloader - Enable Long Mode By Far Jumping & Load Microkernel Code Syntax Using 64 Bit
- +; ================================================================================================
- +
- jmp gdt.kernel_code:long_mode_ap
- -%include "startup-common.asm"
- +; ======================================================================
- +; benOS Bootloader - Import benOS Common Loaders To x86_64 Boot Process
- +; ======================================================================
- +
- + %include "ben_common.asm"
- -startup_arch:
- +; ======================================================================
- +; benOS Bootloader - Initialize benOS Arch
- +; ======================================================================
- +
- +startup_benos_arch:
- cli
- - ; setting up Page Tables
- - ; Identity Mapping first GB
- +
- + ; =============================================================================
- + ; benOS Bootloader - Setup Page Tables and Identity Mapping on First Gigabyte
- + ; ============================================================================
- +
- mov ax, 0x7000
- mov es, ax
- xor edi, edi
- xor eax, eax
- - mov ecx, 6 * 4096 / 4 ;PML4, PDP, 4 PD / moves 4 Bytes at once
- + mov ecx, 6 * 4096 / 4
- cld
- rep stosd
- xor edi, edi
- - ;Link first PML4 and second to last PML4 to PDP
- +
- + ; =============================================================================
- + ; benOS Bootloader - Connect 1st PML4 and 2nd to Last PML4 to PDP
- + ; ============================================================================
- +
- mov DWORD [es:edi], 0x71000 | 1 << 1 | 1
- mov DWORD [es:edi + 510*8], 0x71000 | 1 << 1 | 1
- add edi, 0x1000
- - ;Link last PML4 to PML4
- +
- + ; =============================================================================
- + ; benOS Bootloader - Connect Last PML4 to PDP
- + ; ============================================================================
- +
- mov DWORD [es:edi - 8], 0x70000 | 1 << 1 | 1
- - ;Link first four PDP to PD
- +
- + ; =============================================================================
- + ; benOS Bootloader - Connect All Four PDPs to PD
- + ; ============================================================================
- +
- mov DWORD [es:edi], 0x72000 | 1 << 1 | 1
- mov DWORD [es:edi + 8], 0x73000 | 1 << 1 | 1
- mov DWORD [es:edi + 16], 0x74000 | 1 << 1 | 1
- mov DWORD [es:edi + 24], 0x75000 | 1 << 1 | 1
- add edi, 0x1000
- - ;Link all PD's (512 per PDP, 2MB each)y
- +
- + ; =============================================================================
- + ; benOS Bootloader - Connect All PD's (Max 512 per PDP and 2 megabytes each)
- + ; ============================================================================
- +
- mov ebx, 1 << 7 | 1 << 1 | 1
- mov ecx, 4*512
- +
- +; ======================================================================
- +; benOS Bootloader - Process Data Stage
- +; ======================================================================
- +
- .setpd:
- mov [es:edi], ebx
- add ebx, 0x200000
- @@ -87,61 +168,102 @@ startup_arch:
- xor ax, ax
- mov es, ax
- - ;cr3 holds pointer to PML4
- +; ======================================================================
- +; benOS Bootloader - CR3 Pointer To PML4
- +; ======================================================================
- +
- mov edi, 0x70000
- mov cr3, edi
- - ;enable FXSAVE/FXRSTOR, Page Global, Page Address Extension, and Page Size Extension
- +; =================================================================================
- +; benOS Bootloader - Enable FXSAVE/FXRSTOR, PG Global, PG Address Ext, PG Size Ext
- +; =================================================================================
- +
- mov eax, cr4
- or eax, 1 << 9 | 1 << 7 | 1 << 5 | 1 << 4
- mov cr4, eax
- - ; load protected mode GDT
- +; =================================================================================
- +; benOS Bootloader - Load Protected Mode For Global Descriptor Tables
- +; =================================================================================
- +
- lgdt [gdtr]
- - mov ecx, 0xC0000080 ; Read from the EFER MSR.
- + mov ecx, 0xC0000080 ; Read via the Extended Feature Enable Register Model Specific Registers.
- rdmsr
- - or eax, 1 << 11 | 1 << 8 ; Set the Long-Mode-Enable and NXE bit.
- + or eax, 1 << 11 | 1 << 8 ; Enable Long-Mode-Enable and NXE bit for the USE64 Variable later.
- wrmsr
- - ;enabling paging and protection simultaneously
- +; =======================================================================================
- +; benOS Bootloader - Enable Simultaneous Paging / Protection To Use With 64 Bit Hardware
- +; =======================================================================================
- +
- mov ebx, cr0
- - or ebx, 1 << 31 | 1 << 16 | 1 ;Bit 31: Paging, Bit 16: write protect kernel, Bit 0: Protected Mode
- + or ebx, 1 << 31 | 1 << 16 | 1 ;Bit 31: benOS Paging, Bit 16: Write-Protect benOS Microkernel, Bit 0: Protected Mode
- mov cr0, ebx
- - ; far jump to enable Long Mode and load CS with 64 bit segment
- +; ====================================================================================================
- +; benOS Bootloader - Far Jump-Based Enablement Of benOS Long Mode While Loading Code Syntax + 64 Bit
- +; ====================================================================================================
- +
- jmp gdt.kernel_code:long_mode
- +; ======================================================================
- +; benOS Bootloader - Load USE64 Global Bootloader Function
- +; ======================================================================
- +
- USE64
- +
- +; =================================================================================
- +; benOS Bootloader - Long Mode Loader + Other 64 Bit Data Segments
- +; =================================================================================
- +
- long_mode:
- - ; load all the other segments with 64 bit data segments
- mov rax, gdt.kernel_data
- mov ds, rax
- mov es, rax
- mov fs, rax
- mov gs, rax
- mov ss, rax
- +
- +; =================================================================================
- +; benOS Bootloader - benOS Stack Base
- +; =================================================================================
- - ; stack_base
- mov rsi, 0xFFFFFF0000080000
- mov [args.stack_base], rsi
- - ; stack_size
- +
- +; =================================================================================
- +; benOS Bootloader - benOS Stack Size
- +; =================================================================================
- +
- mov rcx, 0x1F000
- mov [args.stack_size], rcx
- - ; set stack pointer
- +; =================================================================================
- +; benOS Bootloader - benOS Stack Pointer
- +; =================================================================================
- +
- mov rsp, rsi
- add rsp, rcx
- - ; copy env to stack
- +; =================================================================================
- +; benOS Bootloader - Copy Bootloader Environment Variables To benOS Stack
- +; =================================================================================
- +
- %ifdef KERNEL
- mov rsi, 0
- mov rcx, 0
- %else
- - mov rsi, redoxfs.env
- - mov rcx, redoxfs.env.end - redoxfs.env
- + mov rsi, benfs.env
- + mov rcx, benfs.env.end - benfs.env
- %endif
- mov [args.env_size], rcx
- +
- +; =================================================================================
- +; benOS Bootloader - Copy Environment Variables Function
- +; =================================================================================
- +
- .copy_env:
- cmp rcx, 0
- je .no_env
- @@ -150,23 +272,46 @@ long_mode:
- dec rsp
- mov [rsp], al
- jmp .copy_env
- +
- +; =================================================================================
- +; benOS Bootloader - Function When Environment Variables Are Non-Existent
- +; =================================================================================
- +
- .no_env:
- mov [args.env_base], rsp
- - ; align stack
- +; =================================================================================
- +; benOS Bootloader - benOS Stack Alignment
- +; =================================================================================
- +
- and rsp, 0xFFFFFFFFFFFFFFF0
- - ; set args
- +; =================================================================================
- +; benOS Bootloader - Set Arguments From Environment Variables and Microkernel
- +; =================================================================================
- +
- mov rdi, args
- - ; entry point
- +; =================================================================================
- +; benOS Bootloader - benOS Microkernel Entry Point
- +; =================================================================================
- +
- mov rax, [args.kernel_base]
- call [rax + 0x18]
- +
- +; =================================================================================
- +; benOS Bootloader - Halt Stage
- +; =================================================================================
- +
- .halt:
- cli
- hlt
- jmp .halt
- +; =================================================================================
- +; benOS Bootloader - Long Mode AP
- +; =================================================================================
- +
- long_mode_ap:
- mov rax, gdt.kernel_data
- mov ds, rax
- @@ -175,15 +320,20 @@ long_mode_ap:
- mov gs, rax
- mov ss, rax
- - mov rcx, [trampoline.stack_end]
- + mov rcx, [benboot.stack_end]
- lea rsp, [rcx - 256]
- - mov rdi, trampoline.cpu_id
- + mov rdi, benboot.cpu_id
- - mov rax, [trampoline.code]
- - mov qword [trampoline.ready], 1
- + mov rax, [benboot.code]
- + mov qword [benboot.ready], 1
- jmp rax
- +; =================================================================================
- +; benOS Bootloader - Finalization
- +; =================================================================================
- +
- +
- gdtr:
- dw gdt.end + 1 ; size
- dq gdt ; offset
- @@ -207,7 +357,6 @@ istruc GDTEntry
- at GDTEntry.limitl, dw 0
- at GDTEntry.basel, dw 0
- at GDTEntry.basem, db 0
- -; AMD System Programming Manual states that the writeable bit is ignored in long mode, but ss can not be set to this descriptor without it
- at GDTEntry.attribute, db attrib.present | attrib.user | attrib.writable
- at GDTEntry.flags__limith, db 0
- at GDTEntry.baseh, db 0
- diff --git b/benplay.asm a/benplay.asm
- old mode 100755
- new mode 100644
- index 367b2c2..ae8ff22
- --- b/benplay.asm
- +++ a/benplay.asm
- @@ -1,91 +1,162 @@
- -%include "vesa.inc"
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Initialize BenPlay
- +; ------------------------------------------------------------------
- +
- +%include "benplay.inc"
- SECTION .text
- USE16
- -vesa:
- -.getcardinfo:
- +
- +benplay:
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Get Video Card
- +; ------------------------------------------------------------------
- +
- +.getvidcard:
- mov ax, 0x4F00
- - mov di, VBECardInfo
- + mov di, BPBECardInfo
- int 0x10
- cmp ax, 0x4F
- - je .findmode
- + je .findbenmode
- mov eax, 1
- ret
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Reset Configuration List
- +; ------------------------------------------------------------------
- +
- .resetlist:
- - ;if needed, reset mins/maxes/stuff
- xor cx, cx
- mov [.minx], cx
- mov [.miny], cx
- - mov [config.xres], cx
- - mov [config.yres], cx
- -.findmode:
- - mov si, [VBECardInfo.videomodeptr]
- - mov ax, [VBECardInfo.videomodeptr+2]
- + mov [benconfig.xres], cx
- + mov [benconfig.yres], cx
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Find benOS Modes
- +; ------------------------------------------------------------------
- +
- +.findbenmode:
- + mov si, [BPBECardInfo.videomodeptr]
- + mov ax, [BPBECardInfo.videomodeptr+2]
- mov fs, ax
- sub si, 2
- -.searchmodes:
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Locate benOS Modes
- +; ------------------------------------------------------------------
- +
- +.seekbenmodes:
- add si, 2
- mov cx, [fs:si]
- cmp cx, 0xFFFF
- - jne .getmodeinfo
- - cmp word [.goodmode], 0
- + jne .getbenmode
- + cmp word [.bengoodmode], 0
- je .resetlist
- - jmp .findmode
- -.getmodeinfo:
- + jmp .findbenmode
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Get benOS Modes
- +; ------------------------------------------------------------------
- +
- +.getbenmode:
- push esi
- - mov [.currentmode], cx
- + mov [.benmode], cx
- mov ax, 0x4F01
- - mov di, VBEModeInfo
- + mov di, BPBEModeInfo
- int 0x10
- pop esi
- cmp ax, 0x4F
- - je .foundmode
- + je .locatedbenmode
- mov eax, 1
- ret
- -.foundmode:
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Located benOS Mode
- +; ------------------------------------------------------------------
- +
- +.locatedbenmode:
- ;check minimum values, really not minimums from an OS perspective but ugly for users
- - cmp byte [VBEModeInfo.bitsperpixel], 32
- - jb .searchmodes
- + cmp byte [BPBEModeInfo.bitsperpixel], 32
- + jb .seekbenmodes
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Test X Resolution -- Credit: Canonical (MIT)
- +; ------------------------------------------------------------------
- +
- .testx:
- - mov cx, [VBEModeInfo.xresolution]
- - cmp word [config.xres], 0
- + mov cx, [BPBEModeInfo.xresolution]
- + cmp word [benconfig.xres], 0
- je .notrequiredx
- - cmp cx, [config.xres]
- + cmp cx, [benconfig.xres]
- je .testy
- - jmp .searchmodes
- + jmp .seekbenmodes
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Test X Resolution Not Required
- +; ------------------------------------------------------------------
- +
- .notrequiredx:
- cmp cx, [.minx]
- - jb .searchmodes
- + jb .seekbenmodes
- +
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - benOS Testy Bootloader Video Testing Suite
- +; ------------------------------------------------------------------
- +
- .testy:
- - mov cx, [VBEModeInfo.yresolution]
- - cmp word [config.yres], 0
- + mov cx, [BPBEModeInfo.yresolution]
- + cmp word [benconfig.yres], 0
- je .notrequiredy
- - cmp cx, [config.yres]
- - jne .searchmodes ;as if there weren't enough warnings, USE WITH CAUTION
- - cmp word [config.xres], 0
- - jnz .setmode
- - jmp .testgood
- + cmp cx, [benconfig.yres]
- + jne .seekbenmodes ;as if there weren't enough warnings, USE WITH CAUTION
- + cmp word [benconfig.xres], 0
- + jnz .setbenmode
- + jmp .benboot_test
- +
- +; ------------------------------------------------------------------------
- +; benOS Boot Process - benOS Testy Bootloader Video Testing Not Required
- +; ------------------------------------------------------------------------
- +
- +
- .notrequiredy:
- cmp cx, [.miny]
- - jb .searchmodes
- -.testgood:
- + jb .seekbenmodes
- +
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - benOS BenBoot Test w/ BenPlay Mode
- +; ------------------------------------------------------------------
- +
- +.benboot_test:
- mov al, 13
- call print_char
- - mov cx, [.currentmode]
- - mov [.goodmode], cx
- + mov cx, [.benmode]
- + mov [.bengoodmode], cx
- push esi
- - ; call print_dec
- - ; mov al, ':'
- - ; call print_char
- - mov cx, [VBEModeInfo.xresolution]
- + mov cx, [BPBEModeInfo.xresolution]
- call print_dec
- mov al, 'x'
- call print_char
- - mov cx, [VBEModeInfo.yresolution]
- + mov cx, [BPBEModeInfo.yresolution]
- call print_dec
- mov al, '@'
- call print_char
- xor ch, ch
- - mov cl, [VBEModeInfo.bitsperpixel]
- + mov cl, [BPBEModeInfo.bitsperpixel]
- call print_dec
- mov si, .modeok
- call print
- @@ -93,29 +164,52 @@ vesa:
- int 0x16
- pop esi
- cmp al, 'y'
- - je .setmode
- + je .setbenmode
- cmp al, 's'
- - je .savemode
- - jmp .searchmodes
- -.savemode:
- - mov cx, [VBEModeInfo.xresolution]
- + je .savebenmode
- + jmp .seekbenmodes
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - benOS Save BenPlay Video Mode
- +; ------------------------------------------------------------------
- +
- +.savebenmode:
- + mov cx, [BPBEModeInfo.xresolution]
- mov [config.xres], cx
- - mov cx, [VBEModeInfo.yresolution]
- + mov cx, [BPBEModeInfo.yresolution]
- mov [config.yres], cx
- call save_config
- -.setmode:
- - mov bx, [.currentmode]
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - benOS Set BenPlay Video Mode
- +; ------------------------------------------------------------------
- +
- +.setbenmode:
- + mov bx, [.benmode]
- cmp bx, 0
- - je .nomode
- + je .nobenmode
- or bx, 0x4000
- mov ax, 0x4F02
- int 0x10
- -.nomode:
- +
- +; ---------------------------------------------------------------------
- +; benOS Boot Process - When No benOS BenPlay Mode Is Chosen Or Found
- +; ---------------------------------------------------------------------
- +
- +
- +.nobenmode:
- cmp ax, 0x4F
- - je .returngood
- + je .returnbengood
- mov eax, 1
- ret
- -.returngood:
- +
- +
- +; ---------------------------------------------------------------------
- +; benOS Boot Process - Return BenGood Mode
- +; ---------------------------------------------------------------------
- +
- +
- +.returnbengood:
- xor eax, eax
- ret
- @@ -124,17 +218,22 @@ vesa:
- .modeok db ": Is this OK? (s)ave/(y)es/(n)o ",8,8,8,8,0
- -.goodmode dw 0
- -.currentmode dw 0
- -;useful functions
- +.bengoodmode dw 0
- +.benmode dw 0
- +
- +; ---------------------------------------------------------------------
- +; benOS Boot Process - Print Dec
- +; ---------------------------------------------------------------------
- -; print a number in decimal
- -; IN
- -; cx: the number
- -; CLOBBER
- -; al, cx, si
- print_dec:
- mov si, .number
- +
- +
- +; ---------------------------------------------------------------------
- +; benOS Boot Process - Clear Dec
- +; ---------------------------------------------------------------------
- +
- +
- .clear:
- mov al, "0"
- mov [si], al
- @@ -144,12 +243,16 @@ print_dec:
- dec si
- call convert_dec
- mov si, .number
- +
- +
- .lp:
- lodsb
- cmp si, .numberend
- jae .end
- cmp al, "0"
- jbe .lp
- +
- +
- .end:
- dec si
- call print
- @@ -160,39 +263,46 @@ print_dec:
- convert_dec:
- dec si
- - mov bx, si ;place to convert into must be in si, number to convert must be in cx
- + mov bx, si
- +
- .cnvrt:
- mov si, bx
- sub si, 4
- +
- .ten4: inc si
- cmp cx, 10000
- jb .ten3
- sub cx, 10000
- inc byte [si]
- jmp .cnvrt
- +
- .ten3: inc si
- cmp cx, 1000
- jb .ten2
- sub cx, 1000
- inc byte [si]
- jmp .cnvrt
- +
- .ten2: inc si
- cmp cx, 100
- jb .ten1
- sub cx, 100
- inc byte [si]
- jmp .cnvrt
- +
- .ten1: inc si
- cmp cx, 10
- jb .ten0
- sub cx, 10
- inc byte [si]
- jmp .cnvrt
- +
- .ten0: inc si
- cmp cx, 1
- jb .return
- sub cx, 1
- inc byte [si]
- jmp .cnvrt
- +
- .return:
- ret
- diff --git b/benplay.inc a/benplay.inc
- old mode 100755
- new mode 100644
- index 7f85476..a63fc67
- --- b/benplay.inc
- +++ a/benplay.inc
- @@ -1,6 +1,22 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; --------------------------------------------------------------------
- +; benOS Boot Process - BenPlay BIOS Extension Video Card Information
- +; --------------------------------------------------------------------
- +
- ABSOLUTE 0x5000
- -VBECardInfo:
- - .signature resb 4
- +BPBECardInfo:
- + .signature resb 4
- .version resw 1
- .oemstring resd 1
- .capabilities resd 1
- @@ -13,8 +29,12 @@ VBECardInfo:
- .reserved resb 222
- .oemdata resb 256
- +; --------------------------------------------------------------------
- +; benOS Boot Process - BenPlay BIOS Extension Mode Informatiomn
- +; --------------------------------------------------------------------
- +
- ABSOLUTE 0x5200
- -VBEModeInfo:
- +BPBEModeInfo:
- .attributes resw 1
- .winA resb 1
- .winB resb 1
- @@ -49,7 +69,11 @@ VBEModeInfo:
- .offscreenmemsize resw 1
- .reserved resb 206
- -VBE.ModeAttributes:
- +; --------------------------------------------------------------------
- +; benOS Boot Process - BenPlay BIOS Extension Mode Attributes
- +; --------------------------------------------------------------------
- +
- +BPBE.ModeAttributes:
- .available equ 1 << 0
- .bios equ 1 << 2
- .color equ 1 << 3
- @@ -57,9 +81,14 @@ VBE.ModeAttributes:
- .vgacompatible equ 1 << 5
- .notbankable equ 1 << 6
- .linearframebuffer equ 1 << 7
- +
- +
- +; --------------------------------------------------------------------
- +; benOS Boot Process - BenPlay BIOS Extension EDID
- +; --------------------------------------------------------------------
- ABSOLUTE 0x5400
- -VBEEDID:
- +BPBEEDID:
- .header resb 8
- .manufacturer resw 1
- .productid resw 1
- @@ -77,14 +106,14 @@ VBEEDID:
- .timingI resb 1
- .timingII resb 1
- .timingreserved resb 1
- - .standardtiming: resw 8 ;format: db (horizontal-248)/8, aspectratio | verticalfrequency - 60
- - .aspect.16.10 equ 0 ;mul horizontal by 10, shr 4 to get vertical resolution
- - .aspect.4.3 equ 1 << 6 ;mul horizontal by 3, shr 2 to get vertical resolution
- - .aspect.5.4 equ 2 << 6 ;shl horizontal by 2, div by 5 to get vertical resolution
- - .aspect.16.9 equ 3 << 6 ;mul horizontal by 9, shr by 4 to get vertical resolution
- + .standardtiming: resw 8
- + .aspect.16.10 equ 0
- + .aspect.4.3 equ 1 << 6
- + .aspect.5.4 equ 2 << 6
- + .aspect.16.9 equ 3 << 6
- .descriptorblock1 resb 18
- .descriptorblock2 resb 18
- .descriptorblock3 resb 18
- .descriptorblock4 resb 18
- .extensionflag resb 1
- - .checksum resb 1
- \ No newline at end of file
- + .checksum resb 1
- diff --git b/benstart.asm a/benstart.asm
- old mode 100755
- new mode 100644
- index e0ac449..dbda62e
- --- b/benstart.asm
- +++ a/benstart.asm
- @@ -1,20 +1,201 @@
- -SECTION .text
- -USE16
- -
- -initialize:
- -.fpu: ;enable fpu
- - mov eax, cr0
- - and al, 11110011b
- - or al, 00100010b
- - mov cr0, eax
- - mov eax, cr4
- - or eax, 0x200
- - mov cr4, eax
- - fninit
- - ret
- -
- -.sse: ;enable sse
- - mov eax, cr4
- - or ax, 0000011000000000b
- - mov cr4, eax
- - ret
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +
- +ORG 0x7C00
- +SECTION .text
- +USE16
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Starting the Engines
- +; ------------------------------------------------------------------
- +
- +boot: ; dl comes with disk
- + ; benos boot process
- + xor ax, ax
- + mov ds, ax
- + mov es, ax
- + mov ss, ax
- +
- + ; start the benOS engines
- + mov sp, 0x7C00
- +
- + ; start the CS engines
- + push ax
- + push word .init_codeseg
- + retf
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Init Code Segments
- +; ------------------------------------------------------------------
- +
- +.init_codeseg:
- + ; After the boot process, benOS will need to retrieve the number of the primary disk.
- + ; We are able to do that with mov and the [primary-disk].
- + ; After retreiving disk number, it's registered using 'dl', an 8 byte registry.
- + mov [disk], dl
- +
- +
- + mov si, name
- + call print
- + call print_line
- +
- + mov bx, (startup_start - boot) / 512
- + call print_hex
- + call print_line
- +
- + mov bx, startup_start
- + call print_hex
- + call print_line
- +
- + mov eax, (startup_start - boot) / 512
- + mov bx, startup_start
- + mov cx, (startup_end - startup_start) / 512
- + xor dx, dx
- + call load
- +
- + call print_line
- + mov si, finished
- + call print
- + call print_line
- +
- + jmp startup
- +
- +load:
- + cmp cx, 127
- + jbe .ben_ready
- +
- + pusha
- + mov cx, 127
- + call load
- + popa
- + add eax, 127
- + add dx, 127 * 512 / 16
- + sub cx, 127
- +
- + jmp load
- +
- +.ben_ready:
- + mov [BENFIN.addr], eax
- + mov [BENFIN.buf], bx
- + mov [BENFIN.count], cx
- + mov [BENFIN.seg], dx
- +
- + call print_benfin
- +
- + mov dl, [disk]
- + mov si, BENFIN
- + mov ah, 0x42
- + int 0x13
- + jc error
- + ret
- +
- + store:
- + cmp cx, 127
- + jbe .ben_ready
- +
- + pusha
- + mov cx, 127
- + call store
- + popa
- + add ax, 127
- + add dx, 127 * 512 / 16
- + sub cx, 127
- +
- + jmp store
- +
- + .ben_ready:
- + mov [BENFIN.addr], eax
- + mov [BENFIN.buf], bx
- + mov [BENFIN.count], cx
- + mov [BENFIN.seg], dx
- +
- + call print_benfin
- +
- + mov dl, [disk]
- + mov si, BENFIN
- + mov ah, 0x43
- + int 0x13
- + jc error
- + ret ; return ben_ready
- +
- +print_benfin:
- + mov al, 13
- + call print_char
- +
- + mov bx, [BENFIN.addr + 2]
- + call print_hex
- +
- + mov bx, [BENFIN.addr]
- + call print_hex
- +
- + mov al, '#'
- + call print_char
- +
- + mov bx, [BENFIN.count]
- + call print_hex
- +
- + mov al, ' '
- + call print_char
- +
- + mov bx, [BENFIN.seg]
- + call print_hex
- +
- + mov al, ':'
- + call print_char
- +
- + mov bx, [BENFIN.buf]
- + call print_hex
- +
- + ret ; return printed result of BENFIN
- +
- +error:
- + call print_line
- +
- + mov bh, 0
- + mov bl, ah
- + call print_hex
- +
- + mov al, ' '
- + call print_char
- +
- + mov si, errored
- + call print
- + call print_line
- +.halt:
- + cli
- + hlt
- + jmp .halt
- +
- +%include "print.asm"
- +
- +name: db "benOS Loader - Stage1",0
- +errored: db "Was unable to read from local primary disk.",0
- +finished: db "benOS Loader - Stage2",0
- +
- +disk: db 0 ; disk with databyte 0
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - BENFIN
- +; ------------------------------------------------------------------
- +
- +BENFIN:
- + db 0x10
- + db 0
- +.count: dw 0 ; integer 13 resets this to the number of blocks written to/from the primary disk in the boot process.
- +.buf: dw 0 ; Sets 0:7c00 as the memory in-buffer destination address
- +.seg: dw 0 ; Sets zero as the in-memory page, which we will utilize later in the boot process
- +.addr: dq 0 ; put the lba to read in this spot
- +
- +times 510-($-$$) db 0 ; databyte 0
- +db 0x55 ; databyte 1
- +db 0xaa ; databyte 2
- diff --git b/benur.asm a/benur.asm
- old mode 100755
- new mode 100644
- index 691a892..fb379a9
- --- b/benur.asm
- +++ a/benur.asm
- @@ -1,11 +1,26 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- SECTION .text
- USE16
- -; switch to unreal mode; ds and es can address up to 4GiB
- -unreal:
- +; ------------------------------------------------------------------
- +; benOS Bootloader - Switches to BENUR Mode
- +; ------------------------------------------------------------------
- +
- +benur:
- cli
- - lgdt [unreal_gdtr]
- + lgdt [benur_gdtr]
- push es
- push ds
- @@ -16,33 +31,45 @@ unreal:
- jmp $+2
- -; http://wiki.osdev.org/Babystep7
- -; When this register given a "selector", a "segment descriptor cache register"
- -; is filled with the descriptor values, including the size (or limit). After
- -; the switch back to real mode, these values are not modified, regardless of
- -; what value is in the 16-bit segment register. So the 64k limit is no longer
- -; valid and 32-bit offsets can be used with the real-mode addressing rules
- - mov bx, unreal_gdt.data
- +
- +; ------------------------------------------------------------------
- +; benOS Bootloader - When the BENUR register is handed a selector
- +; a "SDCR" (Segment Descriptor Cache Register) is completed with
- +; wht we call descriptor values/data that includes the size of the
- +; value/data itself. When switching back to BENR (BenReal Mode), these
- +; values cannot and are not mutable or modified at this boot stage.
- +; Even with the 16-bit register active in this loader stage, it is still
- +; unable to be modified. At this point, the 64K limitation is invalid
- +; and 32-bit offsets can and are utilized with BENUR addressing rules.
- +; ------------------------------------------------------------------
- +
- + mov bx, benur_gdt.data
- mov es, bx
- mov ds, bx
- - and al,0xFE ; back to realmode
- - mov cr0, eax ; by toggling bit again
- + and al,0xFE ; back to BENUR by
- + mov cr0, eax ; toggling bit again
- pop ds
- pop es
- sti
- ret
- +; ------------------------------------------------------------------
- +; benOS Bootloader - Load BENUR Global Descriptor Tables
- +; ------------------------------------------------------------------
- +benur_gdtr:
- + dw benur_gdt.end + 1 ; size
- + dd benur_gdt ; offset
- -unreal_gdtr:
- - dw unreal_gdt.end + 1 ; size
- - dd unreal_gdt ; offset
- +; ------------------------------------------------------------------
- +; benOS Bootloader - Load BENUR Global Descriptor Tables
- +; ------------------------------------------------------------------
- -unreal_gdt:
- -.null equ $ - unreal_gdt
- +benur_gdt:
- +.null equ $ - benur_gdt
- dq 0
- -.data equ $ - unreal_gdt
- +.data equ $ - benur_gdt
- istruc GDTEntry
- at GDTEntry.limitl, dw 0xFFFF
- at GDTEntry.basel, dw 0x0
- @@ -51,4 +78,4 @@ unreal_gdt:
- at GDTEntry.flags__limith, db 0xFF | flags.granularity | flags.default_operand_size
- at GDTEntry.baseh, db 0x0
- iend
- -.end equ $ - unreal_gdt
- +.end equ $ - benur_gdt
- diff --git b/global_descriptor_table_entry.inc a/global_descriptor_table_entry.inc
- old mode 100755
- new mode 100644
- index 861a78b..c914c67
- --- b/global_descriptor_table_entry.inc
- +++ a/global_descriptor_table_entry.inc
- @@ -1,3 +1,19 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- +; ------------------------------------------------------------------
- +; benOS Boot Process - Load Global Descriptor Table TRUC
- +; ------------------------------------------------------------------
- +
- struc GDTEntry
- .limitl resw 1
- .basel resw 1
- diff --git b/print.asm a/print.asm
- old mode 100755
- new mode 100644
- index a2340d9..49104fc
- --- b/print.asm
- +++ a/print.asm
- @@ -1,21 +1,24 @@
- +; ==================================================================
- +; benOS Bootloader
- +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
- +;
- +; The official bootloader for benOS and BenchX desktop/laptop products.
- +; The first bootloader built for a decentralized operating system.
- +; Many bootloaders were looked at and utilized in the creation of
- +; benOS's BenchX bootloader.
- +;
- +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
- +; ==================================================================
- +
- SECTION .text
- USE16
- -; provide function for printing in x86 real mode
- -; print a string and a newline
- -; CLOBBER
- -; ax
- print_line:
- mov al, 13
- call print_char
- mov al, 10
- jmp print_char
- -; print a string
- -; IN
- -; si: points at zero-terminated String
- -; CLOBBER
- -; si, ax
- print:
- pushf
- cld
- @@ -29,9 +32,6 @@ print:
- popf
- ret
- -; print a character
- -; IN
- -; al: character to print
- print_char:
- pusha
- mov bx, 7
- @@ -39,14 +39,10 @@ print_char:
- int 0x10
- popa
- ret
- -
- -; print a number in hex
- -; IN
- -; bx: the number
- -; CLOBBER
- -; al, cx
- +
- print_hex:
- mov cx, 4
- +
- .lp:
- mov al, bh
- shr al, 4
- @@ -55,6 +51,7 @@ print_hex:
- jb .below_0xA
- add al, 'A' - 0xA - '0'
- +
- .below_0xA:
- add al, '0'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement