Advertisement
ff19

benchlab-benos-bootloaders

Jul 7th, 2018
953
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 71.47 KB | None | 0 0
  1. diff --git b/ben_common.asm a/ben_common.asm
  2. old mode 100755
  3. new mode 100644
  4. index b12978d..58093c1
  5. --- b/ben_common.asm
  6. +++ a/ben_common.asm
  7. @@ -1,3 +1,19 @@
  8. +; ==================================================================
  9. +; benOS Bootloader
  10. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  11. +;
  12. +; The official bootloader for benOS and BenchX desktop/laptop products.
  13. +; The first bootloader built for a decentralized operating system.
  14. +; Many bootloaders were looked at and utilized in the creation of
  15. +; benOS's BenchX bootloader.
  16. +;
  17. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  18. +; ==================================================================
  19. +
  20. +; ------------------------------------------------------------------
  21. +; benOS Common Loaders - Load Kernel Args
  22. +; ------------------------------------------------------------------
  23. +
  24.  SECTION .text
  25.  USE16
  26.  
  27. @@ -9,6 +25,10 @@ args:
  28.      .env_base dq 0
  29.      .env_size dq 0
  30.  
  31. +; ------------------------------------------------------------------
  32. +; benOS Common Loaders - Load Kernel Args
  33. +; ------------------------------------------------------------------
  34. +
  35.  startup:
  36.      ; enable A20-Line via IO-Port 92, might not work on all motherboards
  37.      in al, 0x92
  38. @@ -17,74 +37,119 @@ startup:
  39.  
  40.      %ifdef KERNEL
  41.          mov edi, [args.kernel_base]
  42. -        mov ecx, (kernel_file.end - kernel_file)
  43. +        mov ecx, (benos_kernel_file.end - benos_kernel_file)
  44.          mov [args.kernel_size], ecx
  45.  
  46. -        mov eax, (kernel_file - boot)/512
  47. +        mov eax, (benos_kernel_file - boot)/512
  48.          add ecx, 511
  49.          shr ecx, 9
  50.          call load_extent
  51.      %else
  52. -        call redoxfs
  53. +        call benfs
  54.          test eax, eax
  55.          jnz error
  56.      %endif
  57.  
  58. -    jmp .loaded_kernel
  59. +    jmp .loaded_benos_kernel
  60. +
  61. +.loaded_benos_kernel:
  62. +
  63. +; ------------------------------------------------------------------
  64. +; benOS Common Loaders - benOS Memory Mapping Call
  65. +; ------------------------------------------------------------------
  66.  
  67. -.loaded_kernel:
  68. -    call memory_map
  69. +    call ben_mm
  70.  
  71. -    call vesa
  72. +; ------------------------------------------------------------------
  73. +; benOS Common Loaders - benOS BenPlay Video Loaders / Mode Finder
  74. +; ------------------------------------------------------------------
  75. +
  76. +    call benplay
  77. +
  78. +; ------------------------------------------------------------------
  79. +; benOS Common Loaders - Initialize FPU
  80. +; ------------------------------------------------------------------
  81.  
  82.      mov si, init_fpu_msg
  83.      call print
  84.      call initialize.fpu
  85.  
  86. +; ------------------------------------------------------------------
  87. +; benOS Common Loaders - Initialize SSE
  88. +; ------------------------------------------------------------------
  89. +
  90.      mov si, init_sse_msg
  91.      call print
  92.      call initialize.sse
  93.  
  94. -    mov si, startup_arch_msg
  95. +    mov si, startup_ben_arch_msg
  96.      call print
  97.  
  98. -    jmp startup_arch
  99. +    jmp startup_ben_arch
  100. +
  101. +
  102. +; ------------------------------------------------------------------
  103. +; benOS Common Loaders
  104. +; LOAD DISK 'EXTENT' INTO HIGH MEMORY
  105. +; EAX - Sector Address
  106. +; ECX - Sector Count
  107. +; EDI - Destination
  108. +; ------------------------------------------------------------------
  109.  
  110. -# load a disk extent into high memory
  111. -# eax - sector address
  112. -# ecx - sector count
  113. -# edi - destination
  114.  load_extent:
  115. -    ; loading kernel to 1MiB
  116. -    ; move part of kernel to startup_end via bootsector#load and then copy it up
  117. -    ; repeat until all of the kernel is loaded
  118. +
  119. +; ------------------------------------------------------------------
  120. +; benOS Common Loaders
  121. +; LOADING KERNEL TO 1 MEGABYTE
  122. +; MOVE PARTIAL PIECE OF BENOS MICROKERNEL TO BENOS_LAUNCH_END
  123. +; THEN - COPY IT UP
  124. +; THEN - REPEAT UNTIL ALL OF THE benOS MICROKERNEL HAS BEEN LOADED
  125. +; ------------------------------------------------------------------
  126. +
  127.      buffer_size_sectors equ 127
  128.  
  129.  .lp:
  130.      cmp ecx, buffer_size_sectors
  131.      jb .break
  132.  
  133. -    ; saving counter
  134. +; ------------------------------------------------------------------
  135. +; benOS Common Loaders - Save Counter
  136. +; ------------------------------------------------------------------
  137. +
  138.      push eax
  139.      push ecx
  140.  
  141.      push edi
  142.  
  143. -    ; populating buffer
  144. +; ------------------------------------------------------------------
  145. +; benOS Common Loaders - Populate Buffer
  146. +; ------------------------------------------------------------------
  147. +
  148.      mov ecx, buffer_size_sectors
  149. -    mov bx, startup_end
  150. +    mov bx, benos_launch_end
  151.      mov dx, 0x0
  152.  
  153. -    ; load sectors
  154. +; ------------------------------------------------------------------
  155. +; benOS Common Loaders - Load Sector
  156. +; ------------------------------------------------------------------
  157. +
  158.      call load
  159.  
  160. -    ; set up unreal mode
  161. -    call unreal
  162. +
  163. +; ------------------------------------------------------------------
  164. +; benOS Common Loaders - Setup benUnreal Mode
  165. +; ------------------------------------------------------------------
  166. +
  167. +    call benur
  168.  
  169.      pop edi
  170.  
  171. -    ; move data
  172. -    mov esi, startup_end
  173. +
  174. +; ------------------------------------------------------------------
  175. +; benOS Common Loaders - Move Data To benOS Launch End Stage
  176. +; ------------------------------------------------------------------
  177. +
  178. +    mov esi, benos_launch_end
  179.      mov ecx, buffer_size_sectors * 512 / 4
  180.      cld
  181.      a32 rep movsd
  182. @@ -96,6 +161,11 @@ load_extent:
  183.      sub ecx, buffer_size_sectors
  184.      jmp .lp
  185.  
  186. +
  187. +; ------------------------------------------------------------------------------------
  188. +; benOS Common Loaders - Any Left Over Microkernel Outside The Buffer - Loads Here
  189. +; ------------------------------------------------------------------------------------
  190. +
  191.  .break:
  192.      ; load the part of the kernel that does not fill the buffer completely
  193.      test ecx, ecx
  194. @@ -104,38 +174,61 @@ load_extent:
  195.      push ecx
  196.      push edi
  197.  
  198. -    mov bx, startup_end
  199. +    mov bx, benos_launch_end
  200.      mov dx, 0x0
  201.      call load
  202.  
  203. -    ; moving remnants of kernel
  204. -    call unreal
  205. +
  206. +; ------------------------------------------------------------------
  207. +; benOS Common Loaders - Moving Remnants Of Microkernel
  208. +; ------------------------------------------------------------------
  209. +
  210. +    call benur
  211.  
  212.      pop edi
  213.      pop ecx
  214.  
  215. -    mov esi, startup_end
  216. +    mov esi, benos_launch_end
  217.      shl ecx, 7 ; * 512 / 4
  218.      cld
  219.      a32 rep movsd
  220.  
  221. +
  222. +; ------------------------------------------------------------------
  223. +; benOS Common Loaders - Finalization Of Common Bootloader Stage
  224. +; ------------------------------------------------------------------
  225. +
  226. +
  227.  .finish:
  228.      call print_line
  229.      ret
  230.  
  231. -%include "config.asm"
  232. -%include "descriptor_flags.inc"
  233. -%include "gdt_entry.inc"
  234. -%include "unreal.asm"
  235. -%include "memory_map.asm"
  236. -%include "vesa.asm"
  237. -%include "initialize.asm"
  238. +
  239. +; ------------------------------------------------------------------
  240. +; benOS Common Loaders - Common Imports
  241. +; 'benconfig.asm' - benOS Bootloader Configuration
  242. +; 'ben_df.asm' - benOS Bootloader Diffs
  243. +; 'global_descriptor_table_entry.inc' - benOS GDTE
  244. +; 'benur.asm' - benOS Bootloader BENUR Mode
  245. +; 'ben_mm.asm' - benOS Bootloader Memory Mapping
  246. +; 'benplay.asm' - benOS BenPlay Bootloader Video Config / Driver Loader
  247. +; 'startup_ben.asm' - benOS Bootloader Launcher
  248. +; 'benfs.asm' - benOS Local FileSystem
  249. +; ------------------------------------------------------------------
  250. +
  251. +%include "benconfig.asm"
  252. +%include "ben_df.inc"
  253. +%include "global_descriptor_table_entry.inc"
  254. +%include "benur.asm"
  255. +%include "ben_mm.asm"
  256. +%include "benplay.asm"
  257. +%include "startup_ben.asm"
  258.  %ifndef KERNEL
  259. -    %include "redoxfs.asm"
  260. +    %include "benfs.asm"
  261.  %endif
  262.  
  263. -init_fpu_msg: db "Init FPU",13,10,0
  264. -init_sse_msg: db "Init SSE",13,10,0
  265. -init_pit_msg: db "Init PIT",13,10,0
  266. -init_pic_msg: db "Init PIC",13,10,0
  267. -startup_arch_msg: db "Startup Arch",13,10,0
  268. +init_fpu_msg: db "Initialize FPU",13,10,0
  269. +init_sse_msg: db "Initialize SSE",13,10,0
  270. +init_pit_msg: db "Initialize PIT",13,10,0
  271. +init_pic_msg: db "Initialize PIC",13,10,0
  272. +startup_ben_arch_msg: db "Startup benOS Arch",13,10,0
  273. diff --git b/ben_df.inc a/ben_df.inc
  274. old mode 100755
  275. new mode 100644
  276. index 210c98d..83bd186
  277. --- b/ben_df.inc
  278. +++ a/ben_df.inc
  279. @@ -1,3 +1,19 @@
  280. +; ==================================================================
  281. +; benOS Bootloader
  282. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  283. +;
  284. +; The official bootloader for benOS and BenchX desktop/laptop products.
  285. +; The first bootloader built for a decentralized operating system.
  286. +; Many bootloaders were looked at and utilized in the creation of
  287. +; benOS's BenchX bootloader.
  288. +;
  289. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  290. +; ==================================================================
  291. +
  292. +; ------------------------------------------------------------------
  293. +; benOS Common Loaders - DF Loader / Configuration
  294. +; ------------------------------------------------------------------
  295. +
  296.  attrib:
  297.      .present              equ 1 << 7
  298.      .ring1                equ 1 << 5
  299. diff --git b/ben_mm.asm a/ben_mm.asm
  300. old mode 100755
  301. new mode 100644
  302. index a5cdc70..4d5c30c
  303. --- b/ben_mm.asm
  304. +++ a/ben_mm.asm
  305. @@ -1,32 +1,65 @@
  306. -SECTION .text
  307. -USE16
  308. -;Generate a memory map at 0x500 to 0x5000 (available memory not used for kernel or bootloader)
  309. -memory_map:
  310. -.start  equ 0x0500
  311. -.end    equ 0x5000
  312. -.length equ .end - .start
  313. -
  314. -    xor eax, eax
  315. -    mov di, .start
  316. -    mov ecx, .length / 4 ; moving 4 Bytes at once
  317. -    cld
  318. -    rep stosd
  319. -
  320. -    mov di, .start
  321. -    mov edx, 0x534D4150
  322. -    xor ebx, ebx
  323. -.lp:
  324. -    mov eax, 0xE820
  325. -    mov ecx, 24
  326. -
  327. -    int 0x15
  328. -    jc .done ; Error or finished
  329. -
  330. -    cmp ebx, 0
  331. -    je .done ; Finished
  332. -
  333. -    add di, 24
  334. -    cmp di, .end
  335. -    jb .lp ; Still have buffer space
  336. -.done:
  337. -    ret
  338. +; ==================================================================
  339. +; benOS Bootloader
  340. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  341. +;
  342. +; The official bootloader for benOS and BenchX desktop/laptop products.
  343. +; The first bootloader built for a decentralized operating system.
  344. +; Many bootloaders were looked at and utilized in the creation of
  345. +; benOS's BenchX bootloader.
  346. +;
  347. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  348. +; ==================================================================
  349. +
  350. +; ------------------------------------------------------------------
  351. +; benOS Bootloader - Memory Mapping
  352. +; ------------------------------------------------------------------
  353. +
  354. +SECTION .text
  355. +USE16
  356. +
  357. +; ------------------------------------------------------------------
  358. +; benOS Bootloader - At 0x500 to 0x5000 We Generate A Memory Map
  359. +; /// BenchX Desktop will pull from available memory that hasn't been used.
  360. +; /// At this boot stage the benOS microkernel and bootloader are already utilizing
  361. +; memory from your BenchX Desktop, to startup benOS.
  362. +; ------------------------------------------------------------------
  363. +
  364. +ben_mm:
  365. +.start  equ 0x0500
  366. +.end    equ 0x5000
  367. +.length equ .end - .start
  368. +
  369. +    xor eax, eax
  370. +    mov di, .start
  371. +    mov ecx, .length / 4 ; moving 4 Bytes at once
  372. +    cld
  373. +    rep stosd
  374. +
  375. +    mov di, .start
  376. +    mov edx, 0x534D4150 ;  Set EDX to the magic number 0x534D4150.
  377. +    xor ebx, ebx
  378. +
  379. +; ------------------------------------------------------------------
  380. +; benOS Bootloader - Memory Mapping Loop
  381. +; ------------------------------------------------------------------
  382. +
  383. +.lp:
  384. +    mov eax, 0xE820
  385. +    mov ecx, 24
  386. +
  387. +    int 0x15
  388. +    jc .done ; MM Loop either errors out or finishes.
  389. +
  390. +    cmp ebx, 0
  391. +    je .done ; MM Loop finalizes its boot stage loop process.
  392. +
  393. +    add di, 24
  394. +    cmp di, .end
  395. +    jb .lp ; MM Loop has buffer space available and left over.
  396. +
  397. +; ----------------------------------------------------------------------
  398. +; benOS Bootloader - Memory Mapping Complete, Returns Map > Next Stage
  399. +; ----------------------------------------------------------------------
  400. +
  401. +.done:
  402. +    ret
  403. diff --git b/benconfig.asm a/benconfig.asm
  404. old mode 100755
  405. new mode 100644
  406. index 8e3b220..86cb23d
  407. --- b/benconfig.asm
  408. +++ a/benconfig.asm
  409. @@ -1,17 +1,41 @@
  410. +; ==================================================================
  411. +; benOS Bootloader
  412. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  413. +;
  414. +; The official bootloader for benOS and BenchX desktop/laptop products.
  415. +; The first bootloader built for a decentralized operating system.
  416. +; Many bootloaders were looked at and utilized in the creation of
  417. +; benOS's BenchX bootloader.
  418. +;
  419. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  420. +; ==================================================================
  421. +
  422. +; ------------------------------------------------------------------
  423. +; benOS Boot Process - Configuration Stage
  424. +; ------------------------------------------------------------------
  425. +
  426.  SECTION .text
  427.  USE16
  428.  
  429.  align 512, db 0
  430.  
  431. -config:
  432. +; ------------------------------------------------------------------
  433. +; benOS Boot Process - BenConfig Initializer
  434. +; ------------------------------------------------------------------
  435. +
  436. +benconfig:
  437.    .xres: dw 0
  438.    .yres: dw 0
  439.  
  440. -times 512 - ($ - config) db 0
  441. +times 512 - ($ - benconfig) db 0
  442. +
  443. +; ------------------------------------------------------------------
  444. +; benOS Boot Process - Save BenConfig
  445. +; ------------------------------------------------------------------
  446.  
  447. -save_config:
  448. -    mov eax, (config - boot) / 512
  449. -    mov bx, config
  450. +save_benconfig:
  451. +    mov eax, (benconfig - boot) / 512
  452. +    mov bx, benconfig
  453.      mov cx, 1
  454.      xor dx, dx
  455.      call store
  456. diff --git b/benfs.asm a/benfs.asm
  457. old mode 100755
  458. new mode 100644
  459. index 4264b46..0644ce6
  460. --- b/benfs.asm
  461. +++ a/benfs.asm
  462. @@ -1,12 +1,32 @@
  463. -%define BLOCK_SHIFT 12
  464. -%define BLOCK_SIZE (1 << BLOCK_SHIFT)
  465. +; ==================================================================
  466. +; benOS Bootloader
  467. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  468. +;
  469. +; The official bootloader for benOS and BenchX desktop/laptop products.
  470. +; The first bootloader built for a decentralized operating system.
  471. +; Many bootloaders were looked at and utilized in the creation of
  472. +; benOS's BenchX bootloader.
  473. +;
  474. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  475. +; ==================================================================
  476. +
  477. +%define X_BLOCK_SHIFT 12
  478. +%define X_BLOCK_SIZE (1 << X_BLOCK_SHIFT)
  479. +
  480. +; ------------------------------------------------------------------
  481. +; benOS Initial Extent Structure For Block Data
  482. +; ------------------------------------------------------------------
  483.  
  484.  struc Extent
  485.      .block: resq 1,
  486.      .length: resq 1
  487.  endstruc
  488.  
  489. -struc Node
  490. +; ------------------------------------------------------------------
  491. +; benOS Initial BenUnit Structure
  492. +; ------------------------------------------------------------------
  493. +
  494. +struc BenUnit
  495.      .mode: resw 1
  496.      .uid: resd 1
  497.      .gid: resd 1
  498. @@ -17,192 +37,278 @@ struc Node
  499.      .name: resb 222
  500.      .parent: resq 1
  501.      .next: resq 1
  502. -    .extents: resb (BLOCK_SIZE - 272)
  503. +    .extents: resb (X_BLOCK_SIZE - 272)
  504.  endstruc
  505.  
  506. -struc Header
  507. -    ; Signature, should be b"RedoxFS\0"
  508. -    .signature: resb 8
  509. -    ; Version, should be 2
  510. -    .version: resq 1,
  511. -    ; Disk ID, a 128-bit unique identifier
  512. -    .uuid: resb 16,
  513. -    ; Disk size, in BLOCK_SIZE-byte sectors
  514. +; ------------------------------------------------------------------
  515. +; benOS Initial BenHeader Structure For Data Block Header
  516. +; ------------------------------------------------------------------
  517. +
  518. +struc BenHeader
  519. +    ; benFS Signature
  520. +    ; This should be b"benFS\0". If not, there are major bootloader errors. << IMPORTANT
  521. +    .ben_signature: resb 8
  522. +    ; benFS BenHeader Version
  523. +    .ben_version: resq 1,
  524. +    ; BenchDisk ID, a 128-bit BenchX on-board disk UID
  525. +    .benx_uuid: resb 16,
  526. +    ; BenchDisk size
  527.      .size: resq 1,
  528. -    ; Block of root node
  529. +    ; Block of root benOS benunit within the stack
  530.      .root: resq 1,
  531. -    ; Block of free space node
  532. +    ; Block of free space benOS benunit
  533.      .free: resq 1
  534. -    ; Padding
  535. -    .padding: resb (BLOCK_SIZE - 56)
  536. +    ; benFS BenHeader Padding
  537. +    .padding: resb (X_BLOCK_SIZE - 56)
  538.  endstruc
  539.  
  540. -redoxfs:
  541. -        call redoxfs.open
  542. +; ------------------------------------------------------------------
  543. +; benOS Load benFS along with initial BenHeader
  544. +; ------------------------------------------------------------------
  545. +
  546. +benfs:
  547. +        call benfs.open
  548.          test eax, eax
  549. -        jz .good_header
  550. +        jz .ben_header
  551.          ret
  552.  
  553. -    .good_header:
  554. -        mov eax, [.header + Header.root]
  555. -        mov bx, .dir
  556. -        call .node
  557. +; ------------------------------------------------------------------
  558. +; benOS Load Full BenHeader
  559. +; ------------------------------------------------------------------
  560. +
  561. +    .ben_header:
  562. +        mov eax, [.ben_header + BenHeader.root]
  563. +        mov bx, .ben_dir
  564. +        call .benunit
  565.  
  566. -        jmp redoxfs.root
  567. +        jmp benfs.root
  568.  
  569. -    ; node in eax, buffer in bx
  570. -    .node:
  571. -        shl eax, (BLOCK_SHIFT - 9)
  572. -        add eax, (filesystem - boot)/512
  573. -        mov cx, (BLOCK_SIZE/512)
  574. +; ------------------------------------------------------------------
  575. +; benOS Load BenUnit (Load Disk and benOS FileSystem)
  576. +; ------------------------------------------------------------------
  577. +
  578. +    .benunit:
  579. +        shl eax, (X_BLOCK_SHIFT - 9)
  580. +        add eax, (benos_filesystem - boot)/512
  581. +        mov cx, (X_BLOCK_SIZE/512)
  582.          mov dx, 0
  583.          call load
  584.          call print_line
  585.          ret
  586.  
  587. -        align BLOCK_SIZE, db 0
  588. +        align X_BLOCK_SIZE, db 0
  589. +
  590. +; ------------------------------------------------------------------
  591. +; benOS Load BenHeader
  592. +; ------------------------------------------------------------------
  593.  
  594. -    .header:
  595. -        times BLOCK_SIZE db 0
  596. +    .ben_header:
  597. +        times X_BLOCK_SIZE db 0
  598.  
  599. -    .dir:
  600. -        times BLOCK_SIZE db 0
  601. +; ------------------------------------------------------------------
  602. +; benOS Load BenDir
  603. +; ------------------------------------------------------------------
  604.  
  605. -    .file:
  606. -        times BLOCK_SIZE db 0
  607. +    .ben_dir:
  608. +        times X_BLOCK_SIZE db 0
  609.  
  610. -    .env:
  611. -        db "REDOXFS_UUID="
  612. -    .env.uuid:
  613. +; ------------------------------------------------------------------
  614. +; benOS Load BenFile
  615. +; ------------------------------------------------------------------
  616. +
  617. +    .ben_file:
  618. +        times X_BLOCK_SIZE db 0
  619. +
  620. +    .ben_env:
  621. +        db "BENOSFS_BENX_UUID="
  622. +    .ben_env.uuid:
  623.          db "00000000-0000-0000-0000-000000000000"
  624. -    .env.end:
  625. +    .ben_env.end:
  626.          db 0
  627.  
  628. -redoxfs.open:
  629. +; ------------------------------------------------------------------
  630. +; benOS Open benFS Local File System
  631. +; ------------------------------------------------------------------
  632. +
  633. +benfs.open:
  634.          mov eax, 0
  635. -        mov bx, redoxfs.header
  636. -        call redoxfs.node
  637. +        mov bx, benfs.ben_header
  638. +        call benfs.benunit
  639.  
  640.          mov bx, 0
  641. -    .sig:
  642. -        mov al, [redoxfs.header + Header.signature + bx]
  643. -        mov ah, [.signature + bx]
  644. +
  645. +; ------------------------------------------------------------------
  646. +; benOS Load benFS Signature
  647. +; ------------------------------------------------------------------
  648. +
  649. +    .ben_sig:
  650. +        mov al, [benfs.ben_header + BenHeader.ben_signature + bx]
  651. +        mov ah, [.ben_signature + bx]
  652.          cmp al, ah
  653. -        jne .sig_err
  654. +        jne .ben_sig_err
  655.          inc bx
  656.          cmp bx, 8
  657. -        jl .sig
  658. +        jl .ben_sig
  659.  
  660.          mov bx, 0
  661. -    .ver:
  662. -        mov al, [redoxfs.header + Header.version + bx]
  663. -        mov ah, [.version + bx]
  664. +
  665. +; ------------------------------------------------------------------
  666. +; benOS Load benFS Version
  667. +; ------------------------------------------------------------------
  668. +
  669. +    .ben_ver:
  670. +        mov al, [benfs.ben_header + BenHeader.ben_version + bx]
  671. +        mov ah, [.ben_version + bx]
  672.          cmp al, ah
  673. -        jne .ver_err
  674. +        jne .ben_ver_err
  675.          inc bx
  676. -        jl .ver
  677. +        jl .ben_ver
  678.  
  679. -        lea si, [redoxfs.header + Header.signature]
  680. +        lea si, [benfs.ben_header + BenHeader.signature]
  681.          call print
  682.          mov al, ' '
  683.          call print_char
  684.  
  685. -        mov di, redoxfs.env.uuid
  686. +        mov di, benfs.ben_env.benx_uuid
  687.          xor si, si
  688. -    .uuid:
  689. +
  690. +; ------------------------------------------------------------------
  691. +; benOS Load benFS (benX) UUID
  692. +; ------------------------------------------------------------------
  693. +
  694. +    .benx_uuid:
  695.          cmp si, 4
  696. -        je .uuid.dash
  697. +        je .benx_uuid.dash
  698.          cmp si, 6
  699. -        je .uuid.dash
  700. +        je .benx_uuid.dash
  701.          cmp si, 8
  702. -        je .uuid.dash
  703. +        je .benx_uuid.dash
  704.          cmp si, 10
  705. -        je .uuid.dash
  706. -        jmp .uuid.no_dash
  707. -    .uuid.dash:
  708. +        je .benx_uuid.dash
  709. +        jmp .benx_uuid.no_dash
  710. +
  711. +; ------------------------------------------------------------------
  712. +; benOS Load benFS (benX) UUID DASH, NODASH, CHAR and all below 0xA
  713. +; ------------------------------------------------------------------
  714. +
  715. +    .benx_uuid.dash:
  716.          mov al, '-'
  717.          mov [di], al
  718.          inc di
  719. -    .uuid.no_dash:
  720. -        mov bx, [redoxfs.header + Header.uuid + si]
  721. +    .benx_uuid.no_dash:
  722. +        mov bx, [benfs.ben_header + BenHeader.benx_uuid + si]
  723.          rol bx, 8
  724.  
  725.          mov cx, 4
  726. -    .uuid.char:
  727. +    .benx_uuid.char:
  728.          mov al, bh
  729.          shr al, 4
  730.  
  731.          cmp al, 0xA
  732. -        jb .uuid.below_0xA
  733. +        jb .benx_uuid.below_0xA
  734.  
  735.          add al, 'a' - 0xA - '0'
  736. -    .uuid.below_0xA:
  737. +    .benx_uuid.below_0xA:
  738.          add al, '0'
  739.  
  740.          mov [di], al
  741.          inc di
  742.  
  743.          shl bx, 4
  744. -        loop .uuid.char
  745. +        loop .benx_uuid.char
  746.  
  747.          add si, 2
  748.          cmp si, 16
  749. -        jb .uuid
  750. +        jb .benx_uuid
  751.  
  752. -        mov si, redoxfs.env.uuid
  753. +        mov si, benfs.ben_env.benx_uuid
  754.          call print
  755.          call print_line
  756.  
  757.          xor ax, ax
  758.          ret
  759.  
  760. -    .err_msg: db "Failed to open RedoxFS: ",0
  761. -    .sig_err_msg: db "Signature error",13,10,0
  762. -    .ver_err_msg: db "Version error",13,10,0
  763. +; ------------------------------------------------------------------
  764. +; benOS Load benFS Bootloader Error Messages
  765. +; ------------------------------------------------------------------
  766. +
  767. +    .ben_err_msg: db "benOS bootloader failed to open benFS: ",0
  768. +    .ben_sig_err_msg: db "benFS Signature error",13,10,0
  769. +    .ben_ver_err_msg: db "benFS Version error",13,10,0
  770.  
  771. -    .sig_err:
  772. -        mov si, .err_msg
  773. +; ------------------------------------------------------------------
  774. +; benOS Load benFS Signature Error
  775. +; ------------------------------------------------------------------
  776. +
  777. +    .ben_sig_err:
  778. +        mov si, .ben_err_msg
  779.          call print
  780.  
  781. -        mov si, .sig_err_msg
  782. +        mov si, .ben_sig_err_msg
  783.          call print
  784.  
  785.          mov ax, 1
  786.          ret
  787.  
  788. -    .ver_err:
  789. -        mov si, .err_msg
  790. +; ------------------------------------------------------------------
  791. +; benOS Load benFS Version Error
  792. +; ------------------------------------------------------------------
  793. +
  794. +    .ben_ver_err:
  795. +        mov si, .ben_err_msg
  796.          call print
  797.  
  798. -        mov si, .ver_err_msg
  799. +        mov si, .ben_ver_err_msg
  800.          call print
  801.  
  802.          mov ax, 1
  803.          ret
  804.  
  805. -    .signature: db "RedoxFS",0
  806. -    .version: dq 3
  807. +; ------------------------------------------------------------------
  808. +; benOS Load benFS Signature
  809. +; ------------------------------------------------------------------
  810.  
  811. +    .ben_signature: db "benFS",0
  812.  
  813. -redoxfs.root:
  814. -        lea si, [redoxfs.dir + Node.name]
  815. +; ------------------------------------------------------------------
  816. +; benOS Load benFS Version
  817. +; ------------------------------------------------------------------
  818. +
  819. +    .ben_version: dq 3
  820. +
  821. +
  822. +; ------------------------------------------------------------------
  823. +; benOS Load benFS Root Local FileSystem
  824. +; ------------------------------------------------------------------
  825. +
  826. +benfs.root:
  827. +        lea si, [benfs.ben_dir + BenUnit.name]
  828.          call print
  829.          call print_line
  830.  
  831. +; ------------------------------------------------------------------
  832. +; benOS Load benFS Root Local FileSystem [LOOP]
  833. +; ------------------------------------------------------------------
  834. +
  835.      .lp:
  836.          mov bx, 0
  837. +
  838. +; ------------------------------------------------------------------
  839. +; benOS Load benFS Root Local FileSystem [EXTENTS]
  840. +; ------------------------------------------------------------------
  841. +
  842.      .ext:
  843. -        mov eax, [redoxfs.dir + Node.extents + bx + Extent.block]
  844. +        mov eax, [benfs.ben_dir + BenUnit.extents + bx + Extent.block]
  845.          test eax, eax
  846.          jz .next
  847.  
  848. -        mov ecx, [redoxfs.dir + Node.extents + bx + Extent.length]
  849. +        mov ecx, [benfs.ben_dir + BenUnit.extents + bx + Extent.length]
  850.          test ecx, ecx
  851.          jz .next
  852.  
  853. -        add ecx, BLOCK_SIZE
  854. +        add ecx, X_BLOCK_SIZE
  855.          dec ecx
  856. -        shr ecx, BLOCK_SHIFT
  857. +        shr ecx, X_BLOCK_SHIFT
  858.  
  859.          push bx
  860.  
  861. @@ -210,12 +316,12 @@ redoxfs.root:
  862.          push eax
  863.          push ecx
  864.  
  865. -        mov bx, redoxfs.file
  866. -        call redoxfs.node
  867. +        mov bx, benfs.file
  868. +        call benfs.benunit
  869.  
  870.          mov bx, 0
  871.      .ext_sec_kernel:
  872. -        mov al, [redoxfs.file + Node.name + bx]
  873. +        mov al, [benfs.file + BenUnit.name + bx]
  874.          mov ah, [.kernel_name + bx]
  875.  
  876.          cmp al, ah
  877. @@ -229,7 +335,7 @@ redoxfs.root:
  878.          pop ecx
  879.          pop eax
  880.          pop bx
  881. -        jmp redoxfs.kernel
  882. +        jmp benfs.kernel
  883.  
  884.      .ext_sec_kernel_break:
  885.          pop ecx
  886. @@ -242,18 +348,26 @@ redoxfs.root:
  887.          pop bx
  888.  
  889.          add bx, Extent_size
  890. -        cmp bx, (BLOCK_SIZE - 272)
  891. +        cmp bx, (X_BLOCK_SIZE - 272)
  892.          jb .ext
  893.  
  894. +; ------------------------------------------------------------------
  895. +; benOS Load benFS Next BenUnit
  896. +; ------------------------------------------------------------------
  897. +
  898.      .next:
  899. -        mov eax, [redoxfs.dir + Node.next]
  900. +        mov eax, [benfs.ben_dir + BenUnit.next]
  901.          test eax, eax
  902.          jz .no_kernel
  903.  
  904. -        mov bx, redoxfs.dir
  905. -        call redoxfs.node
  906. +        mov bx, benfs.ben_dir
  907. +        call benfs.benunit
  908.          jmp .lp
  909.  
  910. +; ------------------------------------------------------------------
  911. +; benOS Load benFS - [IF NO KERNEL]
  912. +; ------------------------------------------------------------------
  913. +
  914.      .no_kernel:
  915.          mov si, .no_kernel_msg
  916.          call print
  917. @@ -266,23 +380,42 @@ redoxfs.root:
  918.          mov eax, 1
  919.          ret
  920.  
  921. +
  922. +; ------------------------------------------------------------------
  923. +; benOS Load benFS - Microkernel Information / No Kernel Error Message
  924. +; ------------------------------------------------------------------
  925. +
  926.      .kernel_name: db "kernel",0
  927. -    .no_kernel_msg: db "Did not find: ",0
  928. +    .no_kernel_msg: db "benOS bootloader: Did not find ",0
  929. +
  930. +; ------------------------------------------------------------------
  931. +; benOS Load benFS - Load Microkernel
  932. +; ------------------------------------------------------------------
  933.  
  934. -redoxfs.kernel:
  935. -        lea si, [redoxfs.file + Node.name]
  936. +benfs.kernel:
  937. +        lea si, [benfs.ben_file + BenUnit.name]
  938.          call print
  939.          call print_line
  940.  
  941.          mov edi, [args.kernel_base]
  942. +
  943. +; ------------------------------------------------------------------
  944. +; benOS Load benFS - Microkernel Loader [LOOP]
  945. +; ------------------------------------------------------------------
  946. +
  947.      .lp:
  948.          mov bx, 0
  949. +
  950. +; ------------------------------------------------------------------
  951. +; benOS Load benFS - Microkernel Loader [EXTENTS]
  952. +; ------------------------------------------------------------------
  953. +
  954.      .ext:
  955. -        mov eax, [redoxfs.file + Node.extents + bx + Extent.block]
  956. +        mov eax, [benfs.ben_file + BenUnit.extents + bx + Extent.block]
  957.          test eax, eax
  958.          jz .next
  959.  
  960. -        mov ecx, [redoxfs.file + Node.extents + bx + Extent.length]
  961. +        mov ecx, [benfs.ben_file + BenUnit.extents + bx + Extent.length]
  962.          test ecx, ecx
  963.          jz .next
  964.  
  965. @@ -293,9 +426,9 @@ redoxfs.kernel:
  966.          push edi
  967.  
  968.  
  969. -        shl eax, (BLOCK_SHIFT - 9)
  970. -        add eax, (filesystem - boot)/512
  971. -        add ecx, BLOCK_SIZE
  972. +        shl eax, (X_BLOCK_SHIFT - 9)
  973. +        add eax, (benos_filesystem - boot)/512
  974. +        add ecx, X_BLOCK_SIZE
  975.          dec ecx
  976.          shr ecx, 9
  977.          call load_extent
  978. @@ -312,19 +445,27 @@ redoxfs.kernel:
  979.          cmp bx, Extent_size * 16
  980.          jb .ext
  981.  
  982. +; ------------------------------------------------------------------
  983. +; benOS Load benFS - Load Next BenUnit
  984. +; ------------------------------------------------------------------
  985. +
  986.      .next:
  987. -        mov eax, [redoxfs.file + Node.next]
  988. +        mov eax, [benfs.ben_file + BenUnit.next]
  989.          test eax, eax
  990.          jz .done
  991.  
  992.          push edi
  993.  
  994. -        mov bx, redoxfs.file
  995. -        call redoxfs.node
  996. +        mov bx, benfs.ben_file
  997. +        call benfs.benunit
  998.  
  999.          pop edi
  1000.          jmp .lp
  1001.  
  1002. +; ------------------------------------------------------------------
  1003. +; benOS Load benFS - Finalizing Loading of benFS Local File System
  1004. +; ------------------------------------------------------------------
  1005. +
  1006.      .done:
  1007.          sub edi, [args.kernel_base]
  1008.          mov [args.kernel_size], edi
  1009. diff --git b/benh_disk.asm a/benh_disk.asm
  1010. old mode 100755
  1011. new mode 100644
  1012. index 1ef4cc3..fed8fbb
  1013. --- b/benh_disk.asm
  1014. +++ a/benh_disk.asm
  1015. @@ -1,33 +1,72 @@
  1016. +; ==================================================================
  1017. +; benOS Bootloader
  1018. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  1019. +;
  1020. +; The official bootloader for benOS and BenchX desktop/laptop products.
  1021. +; The first bootloader built for a decentralized operating system.
  1022. +; Many bootloaders were looked at and utilized in the creation of
  1023. +; benOS's BenchX bootloader.
  1024. +;
  1025. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  1026. +; ==================================================================
  1027. +
  1028.  sectalign off
  1029.  
  1030. -%include "bootsector.asm"
  1031. +%include "benstart.asm"
  1032. +
  1033. +; ------------------------------------------------------------------
  1034. +; benOS Launch Start >> i386 or x86_64
  1035. +; ------------------------------------------------------------------
  1036. +
  1037. +benos_launch_start:
  1038. +
  1039. +; ------------------------------------------------------------------
  1040. +; benOS i386 Launch Loader
  1041. +; ------------------------------------------------------------------
  1042.  
  1043. -startup_start:
  1044.  %ifdef ARCH_i386
  1045. -    %include "startup-i386.asm"
  1046. +    %include "benos-i386.asm"
  1047.  %endif
  1048.  
  1049. +; ------------------------------------------------------------------
  1050. +; benOS x86_64 Launch Loader
  1051. +; ------------------------------------------------------------------
  1052. +
  1053.  %ifdef ARCH_x86_64
  1054. -    %include "startup-x86_64.asm"
  1055. +    %include "benos-x86_64.asm"
  1056.  %endif
  1057.  align 512, db 0
  1058. -startup_end:
  1059. +benos_launch_end:
  1060. +
  1061. +; ------------------------------------------------------------------
  1062. +; benOS Microkernel Loader
  1063. +; ------------------------------------------------------------------
  1064.  
  1065.  %ifdef KERNEL
  1066. -    kernel_file:
  1067. +    benos_kernel_file:
  1068.        %defstr KERNEL_STR %[KERNEL]
  1069.        incbin KERNEL_STR
  1070.      .end:
  1071.      align 512, db 0
  1072.  %else
  1073. -    align BLOCK_SIZE, db 0
  1074. -    %ifdef FILESYSTEM
  1075. -        filesystem:
  1076. -            %defstr FILESYSTEM_STR %[FILESYSTEM]
  1077. -            incbin FILESYSTEM_STR
  1078. +
  1079. +; ------------------------------------------------------------------
  1080. +; benOS If Microkernel Has Already Loaded, Load FileSystem
  1081. +; ------------------------------------------------------------------
  1082. +
  1083. +    align X_BLOCK_SIZE, db 0
  1084. +    %ifdef BEN_FILESYSTEM
  1085. +        benos_filesystem:
  1086. +            %defstr BEN_FILESYSTEM_STR %[BEN_FILESYSTEM]
  1087. +            incbin BEN_FILESYSTEM_STR
  1088.          .end:
  1089. -        align BLOCK_SIZE, db 0
  1090. +        align X_BLOCK_SIZE, db 0
  1091. +
  1092. +; --------------------------------------------------------------------------------
  1093. +; benOS If Microkernel and FileSystem Already Loaded, Execute Loaded Filesystem
  1094. +; --------------------------------------------------------------------------------
  1095. +
  1096.      %else
  1097. -        filesystem:
  1098. +        benos_filesystem:
  1099.      %endif
  1100.  %endif
  1101. diff --git b/benos-x86_64.asm a/benos-x86_64.asm
  1102. old mode 100755
  1103. new mode 100644
  1104. index 53dbf16..5b920cb
  1105. --- b/benos-x86_64.asm
  1106. +++ a/benos-x86_64.asm
  1107. @@ -1,4 +1,30 @@
  1108. -trampoline:
  1109. +; ==================================================================
  1110. +; benOS Bootloader
  1111. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  1112. +;
  1113. +; The official bootloader for benOS and BenchX desktop/laptop products.
  1114. +; The first bootloader built for a decentralized operating system.
  1115. +; Many bootloaders were looked at and utilized in the creation of
  1116. +; benOS's BenchX bootloader.
  1117. +;
  1118. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  1119. +; ==================================================================
  1120. +
  1121. +; =================================================================================
  1122. +; benOS Bootloader - BenBoot Stage
  1123. +; =================================================================================
  1124. +
  1125. +; ------------------------------------------------------------------
  1126. +; benOS BenBoot Stage - Step By Step
  1127. +; 1. Check Readiness of benOS Bootloader
  1128. +; 2. Get CPU ID
  1129. +; 3. Initialize Table
  1130. +; 4. Start benOS Stack
  1131. +; 5. Exit benOS Stack
  1132. +; 6. Exit Code
  1133. +; ------------------------------------------------------------------
  1134. +
  1135. +benboot:
  1136.      .ready: dq 0
  1137.      .cpu_id: dq 0
  1138.      .page_table: dq 0
  1139. @@ -6,7 +32,11 @@ trampoline:
  1140.      .stack_end: dq 0
  1141.      .code: dq 0
  1142.  
  1143. -    times 512 - ($ - trampoline) db 0
  1144. +    times 512 - ($ - benboot) db 0
  1145. +
  1146. +; =================================================================================
  1147. +; benOS Bootloader - 'startup_ap' - Initialize benOS Stack
  1148. +; =================================================================================
  1149.  
  1150.  startup_ap:
  1151.      cli
  1152. @@ -16,68 +46,119 @@ startup_ap:
  1153.      mov es, ax
  1154.      mov ss, ax
  1155.  
  1156. -    ; initialize stack
  1157. +; ==================================================================
  1158. +; benOS Bootloader - Initialize benOS Stack, FPU and SSE
  1159. +; ==================================================================
  1160. +
  1161.      mov sp, 0x7C00
  1162.  
  1163.      call initialize.fpu
  1164.      call initialize.sse
  1165.  
  1166. -    ;cr3 holds pointer to PML4
  1167. +; ==================================================================
  1168. +; benOS Bootloader - CR3 Point to PML4
  1169. +; ==================================================================
  1170. +
  1171.      mov edi, 0x70000
  1172.      mov cr3, edi
  1173.  
  1174. -    ;enable FXSAVE/FXRSTOR, Page Global, Page Address Extension, and Page Size Extension
  1175. +
  1176. +; =============================================================================
  1177. +; benOS Bootloader - Enable FXSAVE/FXRSTOR/PG_GLOBAL/PG_ADDR_EXT/PG_SIZE_EXT
  1178. +; =============================================================================
  1179. +
  1180.      mov eax, cr4
  1181.      or eax, 1 << 9 | 1 << 7 | 1 << 5 | 1 << 4
  1182.      mov cr4, eax
  1183.  
  1184. -    ; load protected mode GDT
  1185. +; ======================================================================
  1186. +; benOS Bootloader - Load Global Descriptor Tables In Protected Mode
  1187. +; ======================================================================
  1188. +
  1189.      lgdt [gdtr]
  1190.  
  1191. -    mov ecx, 0xC0000080               ; Read from the EFER MSR.
  1192. +    mov ecx, 0xC0000080               ; Read via the Extended Feature Enable Register Model Specific Registers.
  1193.      rdmsr
  1194. -    or eax, 1 << 11 | 1 << 8          ; Set the Long-Mode-Enable and NXE bit.
  1195. +    or eax, 1 << 11 | 1 << 8          ; Enable Long-Mode-Enable and NXE bit for the USE64 Variable later.
  1196.      wrmsr
  1197.  
  1198. -    ;enabling paging and protection simultaneously
  1199. +; ======================================================================
  1200. +; benOS Bootloader - Enable Simulataneous Paging and Protection
  1201. +; ======================================================================
  1202. +
  1203.      mov ebx, cr0
  1204. -    or ebx, 1 << 31 | 1 << 16 | 1                ;Bit 31: Paging, Bit 16: write protect kernel, Bit 0: Protected Mode
  1205. +    or ebx, 1 << 31 | 1 << 16 | 1     ;Bit 31: benOS Paging, Bit 16: Write-Protected benOS Microkernel, Bit 0: Protected Mode
  1206.      mov cr0, ebx
  1207.  
  1208. -    ; far jump to enable Long Mode and load CS with 64 bit segment
  1209. +; ================================================================================================
  1210. +; benOS Bootloader - Enable Long Mode By Far Jumping & Load Microkernel Code Syntax Using 64 Bit
  1211. +; ================================================================================================
  1212. +
  1213.      jmp gdt.kernel_code:long_mode_ap
  1214.  
  1215. -%include "startup-common.asm"
  1216. +; ======================================================================
  1217. +; benOS Bootloader - Import benOS Common Loaders To x86_64 Boot Process
  1218. +; ======================================================================
  1219. +
  1220. +    %include "ben_common.asm"
  1221.  
  1222. -startup_arch:
  1223. +; ======================================================================
  1224. +; benOS Bootloader - Initialize benOS Arch
  1225. +; ======================================================================
  1226. +
  1227. +startup_benos_arch:
  1228.      cli
  1229. -    ; setting up Page Tables
  1230. -    ; Identity Mapping first GB
  1231. +  
  1232. +    ; =============================================================================
  1233. +    ; benOS Bootloader - Setup Page Tables and Identity Mapping on First Gigabyte
  1234. +    ; ============================================================================
  1235. +
  1236.      mov ax, 0x7000
  1237.      mov es, ax
  1238.  
  1239.      xor edi, edi
  1240.      xor eax, eax
  1241. -    mov ecx, 6 * 4096 / 4 ;PML4, PDP, 4 PD / moves 4 Bytes at once
  1242. +    mov ecx, 6 * 4096 / 4
  1243.      cld
  1244.      rep stosd
  1245.  
  1246.      xor edi, edi
  1247. -    ;Link first PML4 and second to last PML4 to PDP
  1248. +    
  1249. +    ; =============================================================================
  1250. +    ; benOS Bootloader - Connect 1st PML4 and 2nd to Last PML4 to PDP
  1251. +    ; ============================================================================
  1252. +
  1253.      mov DWORD [es:edi], 0x71000 | 1 << 1 | 1
  1254.      mov DWORD [es:edi + 510*8], 0x71000 | 1 << 1 | 1
  1255.      add edi, 0x1000
  1256. -    ;Link last PML4 to PML4
  1257. +
  1258. +    ; =============================================================================
  1259. +    ; benOS Bootloader - Connect Last PML4 to PDP
  1260. +    ; ============================================================================
  1261. +    
  1262.      mov DWORD [es:edi - 8], 0x70000 | 1 << 1 | 1
  1263. -    ;Link first four PDP to PD
  1264. +    
  1265. +    ; =============================================================================
  1266. +    ; benOS Bootloader - Connect All Four PDPs to PD
  1267. +    ; ============================================================================
  1268. +    
  1269.      mov DWORD [es:edi], 0x72000 | 1 << 1 | 1
  1270.      mov DWORD [es:edi + 8], 0x73000 | 1 << 1 | 1
  1271.      mov DWORD [es:edi + 16], 0x74000 | 1 << 1 | 1
  1272.      mov DWORD [es:edi + 24], 0x75000 | 1 << 1 | 1
  1273.      add edi, 0x1000
  1274. -    ;Link all PD's (512 per PDP, 2MB each)y
  1275. +    
  1276. +    ; =============================================================================
  1277. +    ; benOS Bootloader - Connect All PD's (Max 512 per PDP and 2 megabytes each)
  1278. +    ; ============================================================================
  1279. +    
  1280.      mov ebx, 1 << 7 | 1 << 1 | 1
  1281.      mov ecx, 4*512
  1282. +    
  1283. +; ======================================================================
  1284. +; benOS Bootloader - Process Data Stage
  1285. +; ======================================================================
  1286. +
  1287.  .setpd:
  1288.      mov [es:edi], ebx
  1289.      add ebx, 0x200000
  1290. @@ -87,61 +168,102 @@ startup_arch:
  1291.      xor ax, ax
  1292.      mov es, ax
  1293.  
  1294. -    ;cr3 holds pointer to PML4
  1295. +; ======================================================================
  1296. +; benOS Bootloader - CR3 Pointer To PML4
  1297. +; ======================================================================
  1298. +
  1299.      mov edi, 0x70000
  1300.      mov cr3, edi
  1301.  
  1302. -    ;enable FXSAVE/FXRSTOR, Page Global, Page Address Extension, and Page Size Extension
  1303. +; =================================================================================
  1304. +; benOS Bootloader - Enable FXSAVE/FXRSTOR, PG Global, PG Address Ext, PG Size Ext
  1305. +; =================================================================================
  1306. +
  1307.      mov eax, cr4
  1308.      or eax, 1 << 9 | 1 << 7 | 1 << 5 | 1 << 4
  1309.      mov cr4, eax
  1310.  
  1311. -    ; load protected mode GDT
  1312. +; =================================================================================
  1313. +; benOS Bootloader - Load Protected Mode For Global Descriptor Tables
  1314. +; =================================================================================
  1315. +
  1316.      lgdt [gdtr]
  1317.  
  1318. -    mov ecx, 0xC0000080               ; Read from the EFER MSR.
  1319. +    mov ecx, 0xC0000080               ; Read via the Extended Feature Enable Register Model Specific Registers.
  1320.      rdmsr
  1321. -    or eax, 1 << 11 | 1 << 8          ; Set the Long-Mode-Enable and NXE bit.
  1322. +    or eax, 1 << 11 | 1 << 8          ; Enable Long-Mode-Enable and NXE bit for the USE64 Variable later.
  1323.      wrmsr
  1324.  
  1325. -    ;enabling paging and protection simultaneously
  1326. +; =======================================================================================
  1327. +; benOS Bootloader - Enable Simultaneous Paging / Protection To Use With 64 Bit Hardware
  1328. +; =======================================================================================
  1329. +
  1330.      mov ebx, cr0
  1331. -    or ebx, 1 << 31 | 1 << 16 | 1                ;Bit 31: Paging, Bit 16: write protect kernel, Bit 0: Protected Mode
  1332. +    or ebx, 1 << 31 | 1 << 16 | 1     ;Bit 31: benOS Paging, Bit 16: Write-Protect benOS Microkernel, Bit 0: Protected Mode
  1333.      mov cr0, ebx
  1334.  
  1335. -    ; far jump to enable Long Mode and load CS with 64 bit segment
  1336. +; ====================================================================================================
  1337. +; benOS Bootloader - Far Jump-Based Enablement Of benOS Long Mode While Loading Code Syntax + 64 Bit
  1338. +; ====================================================================================================
  1339. +
  1340.      jmp gdt.kernel_code:long_mode
  1341.  
  1342. +; ======================================================================
  1343. +; benOS Bootloader - Load USE64 Global Bootloader Function
  1344. +; ======================================================================
  1345. +
  1346.  USE64
  1347. +
  1348. +; =================================================================================
  1349. +; benOS Bootloader - Long Mode Loader + Other 64 Bit Data Segments
  1350. +; =================================================================================
  1351. +
  1352.  long_mode:
  1353. -    ; load all the other segments with 64 bit data segments
  1354.      mov rax, gdt.kernel_data
  1355.      mov ds, rax
  1356.      mov es, rax
  1357.      mov fs, rax
  1358.      mov gs, rax
  1359.      mov ss, rax
  1360. +    
  1361. +; =================================================================================
  1362. +; benOS Bootloader - benOS Stack Base
  1363. +; =================================================================================
  1364.  
  1365. -    ; stack_base
  1366.      mov rsi, 0xFFFFFF0000080000
  1367.      mov [args.stack_base], rsi
  1368. -    ; stack_size
  1369. +
  1370. +; =================================================================================
  1371. +; benOS Bootloader - benOS Stack Size
  1372. +; =================================================================================
  1373. +
  1374.      mov rcx, 0x1F000
  1375.      mov [args.stack_size], rcx
  1376.  
  1377. -    ; set stack pointer
  1378. +; =================================================================================
  1379. +; benOS Bootloader - benOS Stack Pointer
  1380. +; =================================================================================
  1381. +
  1382.      mov rsp, rsi
  1383.      add rsp, rcx
  1384.  
  1385. -    ; copy env to stack
  1386. +; =================================================================================
  1387. +; benOS Bootloader - Copy Bootloader Environment Variables To benOS Stack
  1388. +; =================================================================================
  1389. +
  1390.  %ifdef KERNEL
  1391.      mov rsi, 0
  1392.      mov rcx, 0
  1393.  %else
  1394. -    mov rsi, redoxfs.env
  1395. -    mov rcx, redoxfs.env.end - redoxfs.env
  1396. +    mov rsi, benfs.env
  1397. +    mov rcx, benfs.env.end - benfs.env
  1398.  %endif
  1399.      mov [args.env_size], rcx
  1400. +    
  1401. +; =================================================================================
  1402. +; benOS Bootloader - Copy Environment Variables Function
  1403. +; =================================================================================
  1404. +
  1405.  .copy_env:
  1406.      cmp rcx, 0
  1407.      je .no_env
  1408. @@ -150,23 +272,46 @@ long_mode:
  1409.      dec rsp
  1410.      mov [rsp], al
  1411.      jmp .copy_env
  1412. +    
  1413. +; =================================================================================
  1414. +; benOS Bootloader - Function When Environment Variables Are Non-Existent
  1415. +; =================================================================================
  1416. +
  1417.  .no_env:
  1418.      mov [args.env_base], rsp
  1419.  
  1420. -    ; align stack
  1421. +; =================================================================================
  1422. +; benOS Bootloader - benOS Stack Alignment
  1423. +; =================================================================================
  1424. +
  1425.      and rsp, 0xFFFFFFFFFFFFFFF0
  1426.  
  1427. -    ; set args
  1428. +; =================================================================================
  1429. +; benOS Bootloader - Set Arguments From Environment Variables and Microkernel
  1430. +; =================================================================================
  1431. +
  1432.      mov rdi, args
  1433.  
  1434. -    ; entry point
  1435. +; =================================================================================
  1436. +; benOS Bootloader - benOS Microkernel Entry Point
  1437. +; =================================================================================
  1438. +
  1439.      mov rax, [args.kernel_base]
  1440.      call [rax + 0x18]
  1441. +
  1442. +; =================================================================================
  1443. +; benOS Bootloader - Halt Stage
  1444. +; =================================================================================
  1445. +
  1446.  .halt:
  1447.      cli
  1448.      hlt
  1449.      jmp .halt
  1450.  
  1451. +; =================================================================================
  1452. +; benOS Bootloader - Long Mode AP
  1453. +; =================================================================================
  1454. +
  1455.  long_mode_ap:
  1456.      mov rax, gdt.kernel_data
  1457.      mov ds, rax
  1458. @@ -175,15 +320,20 @@ long_mode_ap:
  1459.      mov gs, rax
  1460.      mov ss, rax
  1461.  
  1462. -    mov rcx, [trampoline.stack_end]
  1463. +    mov rcx, [benboot.stack_end]
  1464.      lea rsp, [rcx - 256]
  1465.  
  1466. -    mov rdi, trampoline.cpu_id
  1467. +    mov rdi, benboot.cpu_id
  1468.  
  1469. -    mov rax, [trampoline.code]
  1470. -    mov qword [trampoline.ready], 1
  1471. +    mov rax, [benboot.code]
  1472. +    mov qword [benboot.ready], 1
  1473.      jmp rax
  1474.  
  1475. +; =================================================================================
  1476. +; benOS Bootloader - Finalization
  1477. +; =================================================================================
  1478. +
  1479. +
  1480.  gdtr:
  1481.      dw gdt.end + 1  ; size
  1482.      dq gdt          ; offset
  1483. @@ -207,7 +357,6 @@ istruc GDTEntry
  1484.      at GDTEntry.limitl, dw 0
  1485.      at GDTEntry.basel, dw 0
  1486.      at GDTEntry.basem, db 0
  1487. -; 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
  1488.      at GDTEntry.attribute, db attrib.present | attrib.user | attrib.writable
  1489.      at GDTEntry.flags__limith, db 0
  1490.      at GDTEntry.baseh, db 0
  1491. diff --git b/benplay.asm a/benplay.asm
  1492. old mode 100755
  1493. new mode 100644
  1494. index 367b2c2..ae8ff22
  1495. --- b/benplay.asm
  1496. +++ a/benplay.asm
  1497. @@ -1,91 +1,162 @@
  1498. -%include "vesa.inc"
  1499. +; ==================================================================
  1500. +; benOS Bootloader
  1501. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  1502. +;
  1503. +; The official bootloader for benOS and BenchX desktop/laptop products.
  1504. +; The first bootloader built for a decentralized operating system.
  1505. +; Many bootloaders were looked at and utilized in the creation of
  1506. +; benOS's BenchX bootloader.
  1507. +;
  1508. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  1509. +; ==================================================================
  1510. +
  1511. +; ------------------------------------------------------------------
  1512. +; benOS Boot Process - Initialize BenPlay
  1513. +; ------------------------------------------------------------------
  1514. +
  1515. +%include "benplay.inc"
  1516.  SECTION .text
  1517.  USE16
  1518. -vesa:
  1519. -.getcardinfo:
  1520. +
  1521. +benplay:
  1522. +
  1523. +; ------------------------------------------------------------------
  1524. +; benOS Boot Process - Get Video Card
  1525. +; ------------------------------------------------------------------
  1526. +
  1527. +.getvidcard:
  1528.      mov ax, 0x4F00
  1529. -    mov di, VBECardInfo
  1530. +    mov di, BPBECardInfo
  1531.      int 0x10
  1532.      cmp ax, 0x4F
  1533. -    je .findmode
  1534. +    je .findbenmode
  1535.      mov eax, 1
  1536.      ret
  1537. +
  1538. +; ------------------------------------------------------------------
  1539. +; benOS Boot Process - Reset Configuration List
  1540. +; ------------------------------------------------------------------
  1541. +
  1542.   .resetlist:
  1543. -    ;if needed, reset mins/maxes/stuff
  1544.      xor cx, cx
  1545.      mov [.minx], cx
  1546.      mov [.miny], cx
  1547. -    mov [config.xres], cx
  1548. -    mov [config.yres], cx
  1549. -.findmode:
  1550. -    mov si, [VBECardInfo.videomodeptr]
  1551. -    mov ax, [VBECardInfo.videomodeptr+2]
  1552. +    mov [benconfig.xres], cx
  1553. +    mov [benconfig.yres], cx
  1554. +
  1555. +; ------------------------------------------------------------------
  1556. +; benOS Boot Process - Find benOS Modes
  1557. +; ------------------------------------------------------------------
  1558. +
  1559. +.findbenmode:
  1560. +    mov si, [BPBECardInfo.videomodeptr]
  1561. +    mov ax, [BPBECardInfo.videomodeptr+2]
  1562.      mov fs, ax
  1563.      sub si, 2
  1564. -.searchmodes:
  1565. +
  1566. +; ------------------------------------------------------------------
  1567. +; benOS Boot Process - Locate benOS Modes
  1568. +; ------------------------------------------------------------------
  1569. +
  1570. +.seekbenmodes:
  1571.      add si, 2
  1572.      mov cx, [fs:si]
  1573.      cmp cx, 0xFFFF
  1574. -    jne .getmodeinfo
  1575. -    cmp word [.goodmode], 0
  1576. +    jne .getbenmode
  1577. +    cmp word [.bengoodmode], 0
  1578.      je .resetlist
  1579. -    jmp .findmode
  1580. -.getmodeinfo:
  1581. +    jmp .findbenmode
  1582. +
  1583. +; ------------------------------------------------------------------
  1584. +; benOS Boot Process - Get benOS Modes
  1585. +; ------------------------------------------------------------------
  1586. +
  1587. +.getbenmode:
  1588.      push esi
  1589. -    mov [.currentmode], cx
  1590. +    mov [.benmode], cx
  1591.      mov ax, 0x4F01
  1592. -    mov di, VBEModeInfo
  1593. +    mov di, BPBEModeInfo
  1594.      int 0x10
  1595.      pop esi
  1596.      cmp ax, 0x4F
  1597. -    je .foundmode
  1598. +    je .locatedbenmode
  1599.      mov eax, 1
  1600.      ret
  1601. -.foundmode:
  1602. +
  1603. +; ------------------------------------------------------------------
  1604. +; benOS Boot Process - Located benOS Mode
  1605. +; ------------------------------------------------------------------
  1606. +
  1607. +.locatedbenmode:
  1608.      ;check minimum values, really not minimums from an OS perspective but ugly for users
  1609. -    cmp byte [VBEModeInfo.bitsperpixel], 32
  1610. -    jb .searchmodes
  1611. +    cmp byte [BPBEModeInfo.bitsperpixel], 32
  1612. +    jb .seekbenmodes
  1613. +
  1614. +; ------------------------------------------------------------------
  1615. +; benOS Boot Process - Test X Resolution -- Credit: Canonical (MIT)
  1616. +; ------------------------------------------------------------------
  1617. +
  1618.  .testx:
  1619. -    mov cx, [VBEModeInfo.xresolution]
  1620. -    cmp word [config.xres], 0
  1621. +    mov cx, [BPBEModeInfo.xresolution]
  1622. +    cmp word [benconfig.xres], 0
  1623.      je .notrequiredx
  1624. -    cmp cx, [config.xres]
  1625. +    cmp cx, [benconfig.xres]
  1626.      je .testy
  1627. -    jmp .searchmodes
  1628. +    jmp .seekbenmodes
  1629. +
  1630. +; ------------------------------------------------------------------
  1631. +; benOS Boot Process - Test X Resolution Not Required
  1632. +; ------------------------------------------------------------------
  1633. +
  1634.  .notrequiredx:
  1635.      cmp cx, [.minx]
  1636. -    jb .searchmodes
  1637. +    jb .seekbenmodes
  1638. +
  1639. +
  1640. +; ------------------------------------------------------------------
  1641. +; benOS Boot Process - benOS Testy Bootloader Video Testing Suite
  1642. +; ------------------------------------------------------------------
  1643. +
  1644.  .testy:
  1645. -    mov cx, [VBEModeInfo.yresolution]
  1646. -    cmp word [config.yres], 0
  1647. +    mov cx, [BPBEModeInfo.yresolution]
  1648. +    cmp word [benconfig.yres], 0
  1649.      je .notrequiredy
  1650. -    cmp cx, [config.yres]
  1651. -    jne .searchmodes    ;as if there weren't enough warnings, USE WITH CAUTION
  1652. -    cmp word [config.xres], 0
  1653. -    jnz .setmode
  1654. -    jmp .testgood
  1655. +    cmp cx, [benconfig.yres]
  1656. +    jne .seekbenmodes    ;as if there weren't enough warnings, USE WITH CAUTION
  1657. +    cmp word [benconfig.xres], 0
  1658. +    jnz .setbenmode
  1659. +    jmp .benboot_test
  1660. +
  1661. +; ------------------------------------------------------------------------
  1662. +; benOS Boot Process - benOS Testy Bootloader Video Testing Not Required
  1663. +; ------------------------------------------------------------------------
  1664. +
  1665. +
  1666.  .notrequiredy:
  1667.      cmp cx, [.miny]
  1668. -    jb .searchmodes
  1669. -.testgood:
  1670. +    jb .seekbenmodes
  1671. +
  1672. +
  1673. +; ------------------------------------------------------------------
  1674. +; benOS Boot Process - benOS BenBoot Test w/ BenPlay Mode
  1675. +; ------------------------------------------------------------------
  1676. +
  1677. +.benboot_test:
  1678.      mov al, 13
  1679.      call print_char
  1680. -    mov cx, [.currentmode]
  1681. -    mov [.goodmode], cx
  1682. +    mov cx, [.benmode]
  1683. +    mov [.bengoodmode], cx
  1684.      push esi
  1685. -    ; call print_dec
  1686. -    ; mov al, ':'
  1687. -    ; call print_char
  1688. -    mov cx, [VBEModeInfo.xresolution]
  1689. +    mov cx, [BPBEModeInfo.xresolution]
  1690.      call print_dec
  1691.      mov al, 'x'
  1692.      call print_char
  1693. -    mov cx, [VBEModeInfo.yresolution]
  1694. +    mov cx, [BPBEModeInfo.yresolution]
  1695.      call print_dec
  1696.      mov al, '@'
  1697.      call print_char
  1698.      xor ch, ch
  1699. -    mov cl, [VBEModeInfo.bitsperpixel]
  1700. +    mov cl, [BPBEModeInfo.bitsperpixel]
  1701.      call print_dec
  1702.      mov si, .modeok
  1703.      call print
  1704. @@ -93,29 +164,52 @@ vesa:
  1705.      int 0x16
  1706.      pop esi
  1707.      cmp al, 'y'
  1708. -    je .setmode
  1709. +    je .setbenmode
  1710.      cmp al, 's'
  1711. -    je .savemode
  1712. -    jmp .searchmodes
  1713. -.savemode:
  1714. -    mov cx, [VBEModeInfo.xresolution]
  1715. +    je .savebenmode
  1716. +    jmp .seekbenmodes
  1717. +
  1718. +; ------------------------------------------------------------------
  1719. +; benOS Boot Process - benOS Save BenPlay Video Mode
  1720. +; ------------------------------------------------------------------
  1721. +
  1722. +.savebenmode:
  1723. +    mov cx, [BPBEModeInfo.xresolution]
  1724.      mov [config.xres], cx
  1725. -    mov cx, [VBEModeInfo.yresolution]
  1726. +    mov cx, [BPBEModeInfo.yresolution]
  1727.      mov [config.yres], cx
  1728.      call save_config
  1729. -.setmode:
  1730. -    mov bx, [.currentmode]
  1731. +
  1732. +; ------------------------------------------------------------------
  1733. +; benOS Boot Process - benOS Set BenPlay Video Mode
  1734. +; ------------------------------------------------------------------
  1735. +
  1736. +.setbenmode:
  1737. +    mov bx, [.benmode]
  1738.      cmp bx, 0
  1739. -    je .nomode
  1740. +    je .nobenmode
  1741.      or bx, 0x4000
  1742.      mov ax, 0x4F02
  1743.      int 0x10
  1744. -.nomode:
  1745. +
  1746. +; ---------------------------------------------------------------------
  1747. +; benOS Boot Process - When No benOS BenPlay Mode Is Chosen Or Found
  1748. +; ---------------------------------------------------------------------
  1749. +
  1750. +
  1751. +.nobenmode:
  1752.      cmp ax, 0x4F
  1753. -    je .returngood
  1754. +    je .returnbengood
  1755.      mov eax, 1
  1756.      ret
  1757. -.returngood:
  1758. +
  1759. +
  1760. +; ---------------------------------------------------------------------
  1761. +; benOS Boot Process - Return BenGood Mode
  1762. +; ---------------------------------------------------------------------
  1763. +
  1764. +
  1765. +.returnbengood:
  1766.      xor eax, eax
  1767.      ret
  1768.  
  1769. @@ -124,17 +218,22 @@ vesa:
  1770.  
  1771.  .modeok db ": Is this OK? (s)ave/(y)es/(n)o    ",8,8,8,8,0
  1772.  
  1773. -.goodmode dw 0
  1774. -.currentmode dw 0
  1775. -;useful functions
  1776. +.bengoodmode dw 0
  1777. +.benmode dw 0
  1778. +
  1779. +; ---------------------------------------------------------------------
  1780. +; benOS Boot Process - Print Dec
  1781. +; ---------------------------------------------------------------------
  1782.  
  1783. -; print a number in decimal
  1784. -; IN
  1785. -;   cx: the number
  1786. -; CLOBBER
  1787. -;   al, cx, si
  1788.  print_dec:
  1789.      mov si, .number
  1790. +
  1791. +
  1792. +; ---------------------------------------------------------------------
  1793. +; benOS Boot Process - Clear Dec
  1794. +; ---------------------------------------------------------------------
  1795. +
  1796. +
  1797.  .clear:
  1798.      mov al, "0"
  1799.      mov [si], al
  1800. @@ -144,12 +243,16 @@ print_dec:
  1801.      dec si
  1802.      call convert_dec
  1803.      mov si, .number
  1804. +
  1805. +
  1806.  .lp:
  1807.      lodsb
  1808.      cmp si, .numberend
  1809.      jae .end
  1810.      cmp al, "0"
  1811.      jbe .lp
  1812. +
  1813. +
  1814.  .end:
  1815.      dec si
  1816.      call print
  1817. @@ -160,39 +263,46 @@ print_dec:
  1818.  
  1819.  convert_dec:
  1820.      dec si
  1821. -    mov bx, si        ;place to convert into must be in si, number to convert must be in cx
  1822. +    mov bx, si  
  1823. +    
  1824.  .cnvrt:
  1825.      mov si, bx
  1826.      sub si, 4
  1827. +
  1828.  .ten4:    inc si
  1829.      cmp cx, 10000
  1830.      jb .ten3
  1831.      sub cx, 10000
  1832.      inc byte [si]
  1833.      jmp .cnvrt
  1834. +
  1835.  .ten3:    inc si
  1836.      cmp cx, 1000
  1837.      jb .ten2
  1838.      sub cx, 1000
  1839.      inc byte [si]
  1840.      jmp .cnvrt
  1841. +
  1842.  .ten2:    inc si
  1843.      cmp cx, 100
  1844.      jb .ten1
  1845.      sub cx, 100
  1846.      inc byte [si]
  1847.      jmp .cnvrt
  1848. +
  1849.  .ten1:    inc si
  1850.      cmp cx, 10
  1851.      jb .ten0
  1852.      sub cx, 10
  1853.      inc byte [si]
  1854.      jmp .cnvrt
  1855. +
  1856.  .ten0:    inc si
  1857.      cmp cx, 1
  1858.      jb .return
  1859.      sub cx, 1
  1860.      inc byte [si]
  1861.      jmp .cnvrt
  1862. +
  1863.  .return:
  1864.      ret
  1865. diff --git b/benplay.inc a/benplay.inc
  1866. old mode 100755
  1867. new mode 100644
  1868. index 7f85476..a63fc67
  1869. --- b/benplay.inc
  1870. +++ a/benplay.inc
  1871. @@ -1,6 +1,22 @@
  1872. +; ==================================================================
  1873. +; benOS Bootloader
  1874. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  1875. +;
  1876. +; The official bootloader for benOS and BenchX desktop/laptop products.
  1877. +; The first bootloader built for a decentralized operating system.
  1878. +; Many bootloaders were looked at and utilized in the creation of
  1879. +; benOS's BenchX bootloader.
  1880. +;
  1881. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  1882. +; ==================================================================
  1883. +
  1884. +; --------------------------------------------------------------------
  1885. +; benOS Boot Process - BenPlay BIOS Extension Video Card Information
  1886. +; --------------------------------------------------------------------
  1887. +
  1888.  ABSOLUTE 0x5000
  1889. -VBECardInfo:
  1890. -   .signature resb 4
  1891. +BPBECardInfo:
  1892. +   .signature resb 4
  1893.     .version resw 1
  1894.     .oemstring resd 1
  1895.     .capabilities resd 1
  1896. @@ -13,8 +29,12 @@ VBECardInfo:
  1897.     .reserved resb 222
  1898.     .oemdata resb 256
  1899.  
  1900. +; --------------------------------------------------------------------
  1901. +; benOS Boot Process - BenPlay BIOS Extension Mode Informatiomn
  1902. +; --------------------------------------------------------------------
  1903. +
  1904.  ABSOLUTE 0x5200
  1905. -VBEModeInfo:
  1906. +BPBEModeInfo:
  1907.     .attributes resw 1
  1908.     .winA resb 1
  1909.     .winB resb 1
  1910. @@ -49,7 +69,11 @@ VBEModeInfo:
  1911.     .offscreenmemsize resw 1
  1912.     .reserved resb 206
  1913.  
  1914. -VBE.ModeAttributes:
  1915. +; --------------------------------------------------------------------
  1916. +; benOS Boot Process - BenPlay BIOS Extension Mode Attributes
  1917. +; --------------------------------------------------------------------
  1918. +
  1919. +BPBE.ModeAttributes:
  1920.     .available equ 1 << 0
  1921.     .bios equ 1 << 2
  1922.     .color equ 1 << 3
  1923. @@ -57,9 +81,14 @@ VBE.ModeAttributes:
  1924.     .vgacompatible equ 1 << 5
  1925.     .notbankable equ 1 << 6
  1926.     .linearframebuffer equ 1 << 7
  1927. +
  1928. +
  1929. +; --------------------------------------------------------------------
  1930. +; benOS Boot Process - BenPlay BIOS Extension EDID
  1931. +; --------------------------------------------------------------------
  1932.    
  1933.  ABSOLUTE 0x5400
  1934. -VBEEDID:
  1935. +BPBEEDID:
  1936.     .header resb 8
  1937.     .manufacturer resw 1
  1938.     .productid resw 1
  1939. @@ -77,14 +106,14 @@ VBEEDID:
  1940.     .timingI    resb 1
  1941.     .timingII   resb 1
  1942.     .timingreserved resb 1
  1943. -   .standardtiming:    resw 8  ;format: db (horizontal-248)/8, aspectratio | verticalfrequency - 60
  1944. -       .aspect.16.10   equ 0   ;mul horizontal by 10, shr 4 to get vertical resolution
  1945. -       .aspect.4.3 equ 1 << 6  ;mul horizontal by 3, shr 2 to get vertical resolution
  1946. -       .aspect.5.4 equ 2 << 6  ;shl horizontal by 2, div by 5 to get vertical resolution
  1947. -       .aspect.16.9    equ 3 << 6  ;mul horizontal by 9, shr by 4 to get vertical resolution
  1948. +   .standardtiming:    resw 8 
  1949. +       .aspect.16.10   equ 0  
  1950. +       .aspect.4.3 equ 1 << 6 
  1951. +       .aspect.5.4 equ 2 << 6 
  1952. +       .aspect.16.9    equ 3 << 6 
  1953.     .descriptorblock1   resb 18
  1954.     .descriptorblock2   resb 18
  1955.     .descriptorblock3   resb 18
  1956.     .descriptorblock4   resb 18
  1957.     .extensionflag  resb 1
  1958. -   .checksum   resb 1
  1959. \ No newline at end of file
  1960. +   .checksum   resb 1
  1961. diff --git b/benstart.asm a/benstart.asm
  1962. old mode 100755
  1963. new mode 100644
  1964. index e0ac449..dbda62e
  1965. --- b/benstart.asm
  1966. +++ a/benstart.asm
  1967. @@ -1,20 +1,201 @@
  1968. -SECTION .text
  1969. -USE16
  1970. -
  1971. -initialize:
  1972. -.fpu: ;enable fpu
  1973. -    mov eax, cr0
  1974. -    and al, 11110011b
  1975. -    or al, 00100010b
  1976. -    mov cr0, eax
  1977. -    mov eax, cr4
  1978. -    or eax, 0x200
  1979. -    mov cr4, eax
  1980. -    fninit
  1981. -    ret
  1982. -
  1983. -.sse: ;enable sse
  1984. -    mov eax, cr4
  1985. -    or ax, 0000011000000000b
  1986. -    mov cr4, eax
  1987. -    ret
  1988. +; ==================================================================
  1989. +; benOS Bootloader
  1990. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  1991. +;
  1992. +; The official bootloader for benOS and BenchX desktop/laptop products.
  1993. +; The first bootloader built for a decentralized operating system.
  1994. +; Many bootloaders were looked at and utilized in the creation of
  1995. +; benOS's BenchX bootloader.
  1996. +;
  1997. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  1998. +; ==================================================================
  1999. +
  2000. +
  2001. +ORG 0x7C00
  2002. +SECTION .text
  2003. +USE16
  2004. +
  2005. +; ------------------------------------------------------------------
  2006. +; benOS Boot Process - Starting the Engines
  2007. +; ------------------------------------------------------------------
  2008. +
  2009. +boot: ; dl comes with disk
  2010. +    ; benos boot process
  2011. +    xor ax, ax
  2012. +    mov ds, ax
  2013. +    mov es, ax
  2014. +    mov ss, ax
  2015. +
  2016. +    ; start the benOS engines
  2017. +    mov sp, 0x7C00
  2018. +
  2019. +    ; start the CS engines
  2020. +    push ax
  2021. +    push word .init_codeseg
  2022. +    retf
  2023. +
  2024. +; ------------------------------------------------------------------
  2025. +; benOS Boot Process - Init Code Segments
  2026. +; ------------------------------------------------------------------
  2027. +
  2028. +.init_codeseg:
  2029. +    ; After the boot process, benOS will need to retrieve the number of the primary disk.
  2030. +    ; We are able to do that with mov and the [primary-disk].
  2031. +    ; After retreiving disk number, it's registered using 'dl', an 8 byte registry.
  2032. +    mov [disk], dl
  2033. +
  2034. +
  2035. +    mov si, name
  2036. +    call print
  2037. +    call print_line
  2038. +
  2039. +    mov bx, (startup_start - boot) / 512
  2040. +    call print_hex
  2041. +    call print_line
  2042. +
  2043. +    mov bx, startup_start
  2044. +    call print_hex
  2045. +    call print_line
  2046. +
  2047. +    mov eax, (startup_start - boot) / 512
  2048. +    mov bx, startup_start
  2049. +    mov cx, (startup_end - startup_start) / 512
  2050. +    xor dx, dx
  2051. +    call load
  2052. +
  2053. +    call print_line
  2054. +    mov si, finished
  2055. +    call print
  2056. +    call print_line
  2057. +
  2058. +    jmp startup
  2059. +
  2060. +load:
  2061. +    cmp cx, 127
  2062. +    jbe .ben_ready
  2063. +
  2064. +    pusha
  2065. +    mov cx, 127
  2066. +    call load
  2067. +    popa
  2068. +    add eax, 127
  2069. +    add dx, 127 * 512 / 16
  2070. +    sub cx, 127
  2071. +
  2072. +    jmp load
  2073. +
  2074. +.ben_ready:
  2075. +    mov [BENFIN.addr], eax
  2076. +    mov [BENFIN.buf], bx
  2077. +    mov [BENFIN.count], cx
  2078. +    mov [BENFIN.seg], dx
  2079. +
  2080. +    call print_benfin
  2081. +
  2082. +    mov dl, [disk]
  2083. +    mov si, BENFIN
  2084. +    mov ah, 0x42
  2085. +    int 0x13
  2086. +    jc error
  2087. +    ret
  2088. +
  2089. +  store:
  2090. +      cmp cx, 127
  2091. +      jbe .ben_ready
  2092. +
  2093. +      pusha
  2094. +      mov cx, 127
  2095. +      call store
  2096. +      popa
  2097. +      add ax, 127
  2098. +      add dx, 127 * 512 / 16
  2099. +      sub cx, 127
  2100. +
  2101. +      jmp store
  2102. +
  2103. +  .ben_ready:
  2104. +      mov [BENFIN.addr], eax
  2105. +      mov [BENFIN.buf], bx
  2106. +      mov [BENFIN.count], cx
  2107. +      mov [BENFIN.seg], dx
  2108. +
  2109. +      call print_benfin
  2110. +
  2111. +      mov dl, [disk]
  2112. +      mov si, BENFIN
  2113. +      mov ah, 0x43
  2114. +      int 0x13
  2115. +      jc error
  2116. +      ret ; return ben_ready
  2117. +
  2118. +print_benfin:
  2119. +    mov al, 13
  2120. +    call print_char
  2121. +
  2122. +    mov bx, [BENFIN.addr + 2]
  2123. +    call print_hex
  2124. +
  2125. +    mov bx, [BENFIN.addr]
  2126. +    call print_hex
  2127. +
  2128. +    mov al, '#'
  2129. +    call print_char
  2130. +
  2131. +    mov bx, [BENFIN.count]
  2132. +    call print_hex
  2133. +
  2134. +    mov al, ' '
  2135. +    call print_char
  2136. +
  2137. +    mov bx, [BENFIN.seg]
  2138. +    call print_hex
  2139. +
  2140. +    mov al, ':'
  2141. +    call print_char
  2142. +
  2143. +    mov bx, [BENFIN.buf]
  2144. +    call print_hex
  2145. +
  2146. +    ret ; return printed result of BENFIN
  2147. +
  2148. +error:
  2149. +    call print_line
  2150. +
  2151. +    mov bh, 0
  2152. +    mov bl, ah
  2153. +    call print_hex
  2154. +
  2155. +    mov al, ' '
  2156. +    call print_char
  2157. +
  2158. +    mov si, errored
  2159. +    call print
  2160. +    call print_line
  2161. +.halt:
  2162. +    cli
  2163. +    hlt
  2164. +    jmp .halt
  2165. +
  2166. +%include "print.asm"
  2167. +
  2168. +name: db "benOS Loader - Stage1",0
  2169. +errored: db "Was unable to read from local primary disk.",0
  2170. +finished: db "benOS Loader - Stage2",0
  2171. +
  2172. +disk: db 0 ; disk with databyte 0
  2173. +
  2174. +; ------------------------------------------------------------------
  2175. +; benOS Boot Process - BENFIN
  2176. +; ------------------------------------------------------------------
  2177. +
  2178. +BENFIN:
  2179. +        db 0x10
  2180. +        db 0
  2181. +.count: dw 0 ; integer 13 resets this to the number of blocks written to/from the primary disk in the boot process.
  2182. +.buf:   dw 0 ; Sets 0:7c00 as the memory in-buffer destination address
  2183. +.seg:   dw 0 ; Sets zero as the in-memory page, which we will utilize later in the boot process
  2184. +.addr:  dq 0 ; put the lba to read in this spot
  2185. +
  2186. +times 510-($-$$) db 0 ; databyte 0
  2187. +db 0x55 ; databyte 1
  2188. +db 0xaa ; databyte 2
  2189. diff --git b/benur.asm a/benur.asm
  2190. old mode 100755
  2191. new mode 100644
  2192. index 691a892..fb379a9
  2193. --- b/benur.asm
  2194. +++ a/benur.asm
  2195. @@ -1,11 +1,26 @@
  2196. +; ==================================================================
  2197. +; benOS Bootloader
  2198. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  2199. +;
  2200. +; The official bootloader for benOS and BenchX desktop/laptop products.
  2201. +; The first bootloader built for a decentralized operating system.
  2202. +; Many bootloaders were looked at and utilized in the creation of
  2203. +; benOS's BenchX bootloader.
  2204. +;
  2205. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  2206. +; ==================================================================
  2207. +
  2208.  SECTION .text
  2209.  USE16
  2210.  
  2211. -; switch to unreal mode; ds and es can address up to 4GiB
  2212. -unreal:
  2213. +; ------------------------------------------------------------------
  2214. +; benOS Bootloader - Switches to BENUR Mode
  2215. +; ------------------------------------------------------------------
  2216. +
  2217. +benur:
  2218.      cli
  2219.  
  2220. -    lgdt [unreal_gdtr]
  2221. +    lgdt [benur_gdtr]
  2222.  
  2223.      push es
  2224.      push ds
  2225. @@ -16,33 +31,45 @@ unreal:
  2226.  
  2227.      jmp $+2
  2228.  
  2229. -; http://wiki.osdev.org/Babystep7
  2230. -; When this register given a "selector", a "segment descriptor cache register"
  2231. -; is filled with the descriptor values, including the size (or limit). After
  2232. -; the switch back to real mode, these values are not modified, regardless of
  2233. -; what value is in the 16-bit segment register. So the 64k limit is no longer
  2234. -; valid and 32-bit offsets can be used with the real-mode addressing rules
  2235. -    mov bx, unreal_gdt.data
  2236. +
  2237. +; ------------------------------------------------------------------
  2238. +; benOS Bootloader - When the BENUR register is handed a selector
  2239. +; a "SDCR" (Segment Descriptor Cache Register) is completed with
  2240. +; wht we call descriptor values/data that includes the size of the
  2241. +; value/data itself. When switching back to BENR (BenReal Mode), these
  2242. +; values cannot and are not mutable or modified at this boot stage.
  2243. +; Even with the 16-bit register active in this loader stage, it is still
  2244. +; unable to be modified. At this point, the 64K limitation is invalid
  2245. +; and 32-bit offsets can and are utilized with BENUR addressing rules.
  2246. +; ------------------------------------------------------------------
  2247. +
  2248. +    mov bx, benur_gdt.data
  2249.      mov es, bx
  2250.      mov ds, bx
  2251.  
  2252. -    and al,0xFE            ; back to realmode
  2253. -    mov  cr0, eax          ; by toggling bit again
  2254. +    and al,0xFE            ; back to BENUR by
  2255. +    mov  cr0, eax          ; toggling bit again
  2256.  
  2257.      pop ds
  2258.      pop es
  2259.      sti
  2260.      ret
  2261.  
  2262. +; ------------------------------------------------------------------
  2263. +; benOS Bootloader - Load BENUR Global Descriptor Tables
  2264. +; ------------------------------------------------------------------
  2265. +benur_gdtr:
  2266. +    dw benur_gdt.end + 1  ; size
  2267. +    dd benur_gdt          ; offset
  2268.  
  2269. -unreal_gdtr:
  2270. -    dw unreal_gdt.end + 1  ; size
  2271. -    dd unreal_gdt          ; offset
  2272. +; ------------------------------------------------------------------
  2273. +; benOS Bootloader - Load BENUR Global Descriptor Tables
  2274. +; ------------------------------------------------------------------
  2275.  
  2276. -unreal_gdt:
  2277. -.null equ $ - unreal_gdt
  2278. +benur_gdt:
  2279. +.null equ $ - benur_gdt
  2280.      dq 0
  2281. -.data equ $ - unreal_gdt
  2282. +.data equ $ - benur_gdt
  2283.      istruc GDTEntry
  2284.          at GDTEntry.limitl,        dw 0xFFFF
  2285.          at GDTEntry.basel,         dw 0x0
  2286. @@ -51,4 +78,4 @@ unreal_gdt:
  2287.          at GDTEntry.flags__limith, db 0xFF | flags.granularity | flags.default_operand_size
  2288.          at GDTEntry.baseh,         db 0x0
  2289.      iend
  2290. -.end equ $ - unreal_gdt
  2291. +.end equ $ - benur_gdt
  2292. diff --git b/global_descriptor_table_entry.inc a/global_descriptor_table_entry.inc
  2293. old mode 100755
  2294. new mode 100644
  2295. index 861a78b..c914c67
  2296. --- b/global_descriptor_table_entry.inc
  2297. +++ a/global_descriptor_table_entry.inc
  2298. @@ -1,3 +1,19 @@
  2299. +; ==================================================================
  2300. +; benOS Bootloader
  2301. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  2302. +;
  2303. +; The official bootloader for benOS and BenchX desktop/laptop products.
  2304. +; The first bootloader built for a decentralized operating system.
  2305. +; Many bootloaders were looked at and utilized in the creation of
  2306. +; benOS's BenchX bootloader.
  2307. +;
  2308. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  2309. +; ==================================================================
  2310. +
  2311. +; ------------------------------------------------------------------
  2312. +; benOS Boot Process - Load Global Descriptor Table TRUC
  2313. +; ------------------------------------------------------------------
  2314. +
  2315.  struc GDTEntry
  2316.      .limitl resw 1
  2317.      .basel resw 1
  2318. diff --git b/print.asm a/print.asm
  2319. old mode 100755
  2320. new mode 100644
  2321. index a2340d9..49104fc
  2322. --- b/print.asm
  2323. +++ a/print.asm
  2324. @@ -1,21 +1,24 @@
  2325. +; ==================================================================
  2326. +; benOS Bootloader
  2327. +; Copyright (C) 2018 Bench Computer, Inc. -- see ~/LICENSE
  2328. +;
  2329. +; The official bootloader for benOS and BenchX desktop/laptop products.
  2330. +; The first bootloader built for a decentralized operating system.
  2331. +; Many bootloaders were looked at and utilized in the creation of
  2332. +; benOS's BenchX bootloader.
  2333. +;
  2334. +; Bootloaders we utilized: Ubuntu, MikeOS, Debian, Linux Mint, ReOS
  2335. +; ==================================================================
  2336. +
  2337.  SECTION .text
  2338.  USE16
  2339. -; provide function for printing in x86 real mode
  2340.  
  2341. -; print a string and a newline
  2342. -; CLOBBER
  2343. -;   ax
  2344.  print_line:
  2345.      mov al, 13
  2346.      call print_char
  2347.      mov al, 10
  2348.      jmp print_char
  2349.  
  2350. -; print a string
  2351. -; IN
  2352. -;   si: points at zero-terminated String
  2353. -; CLOBBER
  2354. -;   si, ax
  2355.  print:
  2356.      pushf
  2357.      cld
  2358. @@ -29,9 +32,6 @@ print:
  2359.      popf
  2360.      ret
  2361.  
  2362. -; print a character
  2363. -; IN
  2364. -;   al: character to print
  2365.  print_char:
  2366.      pusha
  2367.      mov bx, 7
  2368. @@ -39,14 +39,10 @@ print_char:
  2369.      int 0x10
  2370.      popa
  2371.      ret
  2372. -
  2373. -; print a number in hex
  2374. -; IN
  2375. -;   bx: the number
  2376. -; CLOBBER
  2377. -;   al, cx
  2378. +    
  2379.  print_hex:
  2380.      mov cx, 4
  2381. +
  2382.  .lp:
  2383.      mov al, bh
  2384.      shr al, 4
  2385. @@ -55,6 +51,7 @@ print_hex:
  2386.      jb .below_0xA
  2387.  
  2388.      add al, 'A' - 0xA - '0'
  2389. +
  2390.  .below_0xA:
  2391.      add al, '0'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement