From 6ba7a1e098a763a6387e147e8c8656640d342b2b Mon Sep 17 00:00:00 2001 From: Sylar Date: Mon, 31 Mar 2025 10:10:43 +0200 Subject: [PATCH] Started DragonOS groundwork --- .vscode/settings.json | 7 +- extra/dragon/disk1.dr | Bin 4194304 -> 4194304 bytes extra/dss/DragonOS/kernel0.dss | 63 ++++ extra/dss/DragonOS/keyboard_driver.dss | 10 + extra/dss/DragonOS/palette.dss | 45 +++ extra/dss/bios/data.dss | 27 ++ extra/dss/bios_api.dss | 21 ++ extra/dss/drake/bootsector.dss | 395 ++++++++++++++++--------- extra/info/info | 11 + extra/make_and_debug | 1 + extra/make_and_run | 1 + extra/scripts/build_dragonos | 18 ++ src/assembler/Assembler.cpp | 39 +++ src/assembler/Assembler.hpp | 3 + src/gui/Window.hpp | 6 +- src/hardware/VirtualDisplay.cpp | 1 + src/tools/GlobalData.hpp | 50 ++-- 17 files changed, 538 insertions(+), 160 deletions(-) create mode 100644 extra/dss/DragonOS/kernel0.dss create mode 100644 extra/dss/DragonOS/keyboard_driver.dss create mode 100644 extra/dss/DragonOS/palette.dss create mode 100644 extra/scripts/build_dragonos diff --git a/.vscode/settings.json b/.vscode/settings.json index 7c4c32f..cc7fc4b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -100,7 +100,12 @@ "stdfloat": "cpp", "*.inc": "cpp", "text_encoding": "cpp", - "__split_buffer": "cpp" + "__split_buffer": "cpp", + "print": "cpp", + "__hash_table": "cpp", + "execution": "cpp", + "ios": "cpp", + "locale": "cpp" }, "workbench.editorAssociations": { "*.bin": "hexEditor.hexedit" diff --git a/extra/dragon/disk1.dr b/extra/dragon/disk1.dr index 5432417d985a6d008c7550c9413c5ff5beae557e..39adc53b892163c3785fe829251295d8a82e2075 100644 GIT binary patch delta 1135 zcmeHFL2J}d5S}F4w7gArU-D>^mz46hw#9|#BIrSi;6hbISevr!LJtZpty*cDHr+zO zg1ESJfWVuXS!kQ5Y?Xd!bkl!`9mR_NLfdi&|T)t#J21JPZ$aH!771G)bAaNHbsN zhk3#Gh2Rm;0zjD`6c&oSRV`w?NEwu<&G*kQR|}S2IO2bx*l5}a1GV7Axo8B=QsC4A zQ0xA&m;$B4bf>oGEuMXBd$$AL3qYy+@7mty03h+F@1j%pe^TbGT-4c-_W_jDXDo15 zS6IMz0?_K-7faV74E8B;mZ-^hEQ8Dvs1ANUG2;>eH7=Q;4i6s5LEK4Tk4Ug=18Lgl zLTO7#>hsqlF8wBU-ZZI!oRB}Str$sB{|420ZBo}GUp;$YH7wnD>R-yYz3&z?;&}!e zv0%hESz0zOF|2K}NgKJ?AY9Y7G~<55GyDBCA#tb%{YF}i{?h=qyc*Bb^hN3ud@=1N zc`-Y91VoCuBtPn<_glZ-5xfP0A1b&qP4EN2HfJr14EEH>qL>kpVU$|@`5=r@Gs#Ef zXoPr(Tv)K2B+>`!ZY`k zt31Y0_D&{dI&Im601;v=jN**hLoJbZdpWt?d)IrE`w45pASTdry!HkmY33r)88^c5`a7x`z-~Iw}!6|M4 delta 818 zcmeH^ze)o^5XSfZc`&(AM-m$A7 z?M|W!&4hqJ2xt)3A*2eSQ%-^OQ|PDM3@Ny22*x$vVU}|agZ`t%L%t@mM9WyY;1oXI z9waYGqP5_@%S{O{}Tr~A*r`^HbFlvtqlo*vHRf}M0dt9qH)OSkM*>I9)9!*Sh=AYcA z;xHG%5LgWZ^Ar4Jkuf`-^Ki=k9#7dWgM*2WZZcN(e-w^NsmyZWkK*A{)=`ar8s1ur f8L61tyGT1QhW`8l?d7lY+VQ~6zy8;+9Xx*lYc<>E diff --git a/extra/dss/DragonOS/kernel0.dss b/extra/dss/DragonOS/kernel0.dss new file mode 100644 index 0000000..7a3c03a --- /dev/null +++ b/extra/dss/DragonOS/kernel0.dss @@ -0,0 +1,63 @@ +.load 0x2C00 +.fixed 1024, 0xFF +.entry _kernel0_main +.header KERNEL0_BOOT + +@include <../bios_api.dss> +@include + + +## ========================================================================================================================= +.data + $textCell + $test_str "Hello DragonOS! :)" + +## ========================================================================================================================= + + + + +## ========================================================================================================================= +.code +_kernel0_main: + push DefaultPalette.Black + push 1 + call $_clear_screen + debug_break + push $test_str + push 1 + call $_print_string + hlt +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_print_string: ## _print_string(string* str) + arg R1 ## @Param: str + movb [$textCell.CoordX], 0 + movb [$textCell.CoordY], 0 + movb [$textCell.Foreground], DefaultPalette.Blue + movb [$textCell.Background], DefaultPalette.Black + mov R10, 0x22 + mov R8, R1 + mov R9, $textCell + int 0x30 + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_clear_screen: ## _clear_screen(int8_t color) + arg R1 + movb [$textCell.Foreground], R1 + movb [$textCell.Background], R1 + movb [$textCell.Character], 0x20 + mov R10, 0x24 + mov R9, $textCell + int 0x30 + ret +## ========================================================================================================================= \ No newline at end of file diff --git a/extra/dss/DragonOS/keyboard_driver.dss b/extra/dss/DragonOS/keyboard_driver.dss new file mode 100644 index 0000000..6caee03 --- /dev/null +++ b/extra/dss/DragonOS/keyboard_driver.dss @@ -0,0 +1,10 @@ +@guard _KEYBOARD_DRIVER_DSS_ + +.code + +_init_keyboard: ## _init_keyboard(func_ptr* key_pressed_handler) + arg R9 ## @Param: key_pressed_handler + mov R10, 0x00 ## int 0x20 param for set_interrupt_handler + mov R8, 0xA0 ## 0xA0 is the hardware interrupt for KeyPressed + int 0x20 + ret \ No newline at end of file diff --git a/extra/dss/DragonOS/palette.dss b/extra/dss/DragonOS/palette.dss new file mode 100644 index 0000000..e87d486 --- /dev/null +++ b/extra/dss/DragonOS/palette.dss @@ -0,0 +1,45 @@ +@guard _PALETTE_DSS_ + +@group DefaultPalette + Black 0x00 + Gray 0x01 + White 0x02 + Red 0x03 + Pink 0x04 + Brown 0x05 + DarkOrange 0x06 + Orange 0x07 + Yellow 0x08 + DarkGreen 0x09 + Green 0x0A + Lime 0x0B + DarkBlue 0x0C + Blue 0x0D + LightBlue 0x0E + Sky 0x0F +@end + +.code + +_draw_palette: ## _draw_palette(word x, word y) + arg R1 + movb [$textCell.CoordX], R1 + arg R2 + movb [$textCell.CoordY], R2 + movb [$textCell.Character], 0x20 + movb [$textCell.Foreground], 0 + mov R5, 0 +_draw_palette_loop: + movb [$textCell.Background], R5 + movb R6, [$textCell.CoordX] + inc R6 + movb [$textCell.CoordX], R6 + + mov R10, 0x21 + mov R9, $textCell + int 0x30 + + inc R5 + mov ACC, R5 + jge $_draw_palette_loop, 15 + ret \ No newline at end of file diff --git a/extra/dss/bios/data.dss b/extra/dss/bios/data.dss index 0a1dcbe..a8520ec 100644 --- a/extra/dss/bios/data.dss +++ b/extra/dss/bios/data.dss @@ -178,6 +178,20 @@ @raw_export_end @export_comment BIOS_API " --\n" +@export_comment BIOS_API " Structure of a Bootable partitions (Dragon Partition Table)." +@raw_export_start BIOS_API +@group DPTBootPartStructure + ID_ADDR 0x0000 + CODE_START 0x0020 + + ID_CODE 0xF1C4 + CODE_SIZE_B 1024 + HEADER_SIZE_B 32 + CODE_LOAD_ADDR 0x2C00 +@end +@raw_export_end +@export_comment BIOS_API " --\n" + @export_comment BIOS_API " Structure to store a DPT block." @raw_export_start BIOS_API @@ -193,6 +207,19 @@ @export_comment BIOS_API " --\n" +@export_comment BIOS_API " Structure to store a DPT Partition block." +@raw_export_start BIOS_API +@struct DPTPartitionBlock + StartAddress:4 + Size:4 + Flags:2 + Reserved:26 + Label:64 +@end +@raw_export_end +@export_comment BIOS_API " --\n" + + @export_comment BIOS_API " Structure to store a character cell for the Text16-Video-Mode." @raw_export_start BIOS_API @struct Text16VModeCell diff --git a/extra/dss/bios_api.dss b/extra/dss/bios_api.dss index 92d7409..8fd1d90 100644 --- a/extra/dss/bios_api.dss +++ b/extra/dss/bios_api.dss @@ -119,6 +119,17 @@ @end ## -- +## Structure of a Bootable partitions (Dragon Partition Table). +@group DPTBootPartStructure + ID_ADDR 0x0000 + CODE_START 0x0020 + ID_CODE 0xF1C4 + CODE_SIZE_B 1024 + HEADER_SIZE_B 32 + CODE_LOAD_ADDR 0x2C00 +@end +## -- + ## Structure to store a DPT block. @struct DPTBlock ID:2 @@ -130,6 +141,16 @@ @end ## -- +## Structure to store a DPT Partition block. +@struct DPTPartitionBlock + StartAddress:4 + Size:4 + Flags:2 + Reserved:26 + Label:64 +@end +## -- + ## Structure to store a character cell for the Text16-Video-Mode. @struct Text16VModeCell Character:1 diff --git a/extra/dss/drake/bootsector.dss b/extra/dss/drake/bootsector.dss index cee54a0..70e4062 100644 --- a/extra/dss/drake/bootsector.dss +++ b/extra/dss/drake/bootsector.dss @@ -6,6 +6,8 @@ @include @include +@define OS_LOAD_ADDR 0x2C00 + ## ========================================================================================================================= @@ -13,6 +15,8 @@ ## Disk data structures $ddd $dpt_block + $bootstrap_block:32 + $bootstrap_addr:4 $textCell $counter 0x00 @@ -21,6 +25,7 @@ $dpt_version_str "DPT Version " $drake_version_str "Drake 0.2 -- " $invalid_dpt_block_str "Error: Invalid DPT Block..." + $no_part_found_str "Error: No bootable partitions found..." ## ========================================================================================================================= @@ -44,9 +49,9 @@ _drake_bootsector_entry_point: jne $_invalid_dpt_block, 0xF1CA ## Init Keyboard driver - push $_key_pressed ## KeyPressed handler address passed to the _init_keyboard subroutine - push 1 - call $_init_keyboard + ## push $_key_pressed ## KeyPressed handler address passed to the _init_keyboard subroutine + ## push 1 + ## call $_init_keyboard ## Enable Double buffering ## mov R2, [VGA_Registers.FLAGS] @@ -70,7 +75,7 @@ _invalid_dpt_block: ## TODO: Fix screen drawing on error _endless_loop: ## Clear screen - push DefaultPalette.DarkBlue + push DefaultPalette.Black push 1 call $_clear_screen @@ -79,14 +84,58 @@ _endless_loop: call $_print_system_info ## Draw main box - push 0 - call $_print_main_box + ## push 0 + ## call $_print_main_box ## Swap the buffers - push 0 - call $_swap_buffers + ## push 0 + ## call $_swap_buffers - jmp $_endless_loop + mov R10, $dpt_block.PartCount + movb ACC, *R10 + jge $_no_partitions_found, 1 + + mov R10, $dpt_block.PartCount + movb R10, *R10 + push $dpt_block.Entries + push R10 + push $bootstrap_addr + push 3 + call $_test_partitions + mov ACC, RV + jeq $_no_partitions_found, 0xFF + + mov R1, $ddd + mov R4, $bootstrap_addr + + mov R3, R1 ## Copy $ddd address into R3 + movb *R1, DiskMode.READ ## $ddd.Mode + inc R1 + movb *R1, 0x00 ## $ddd.Disk + inc R1 + mov *R1, *R4 ## $ddd.Sector + addip R1, 2 + addip R4, 2 + mov *R1, *R4 ## $ddd.Address + addip R1, 2 + mov *R1, 1024 ## $ddd.DataSize + addip R1, 2 + mov *R1, OS_LOAD_ADDR ## $ddd.MemoryAddress + mov R9, R3 ## Move original $ddd address into R9 (for int 0x20) + mov R10, 0x12 ## int 0x20 parameter for load_from_ddd_blocking + int 0x20 ## Bios interrupt + + debug_break + jmp OS_LOAD_ADDR + jmp $_main_end + +_no_partitions_found: + push $no_part_found_str + push 1 + call $_print_error_msg + jmp $_main_end + + ## jmp $_endless_loop _main_end: hlt ## ========================================================================================================================= @@ -95,10 +144,73 @@ _main_end: ## ========================================================================================================================= -_key_pressed: - mov ACC, [Keyboard_Registers.KEYCODE] - jne $_key_pressed_end, 0x0127 -_key_pressed_end: +_test_partitions: ## _test_partitions(DPTBlock* dpt_entries_block, (1 Byte) dpt_entries_count, (4 Bytes*) part_addr) + arg R1 ## dpt_entries_block + arg R2 ## dpt_entries_count + arg R4 ## part_addr + mov R3, 0 ## Entry counter +_test_partitions_loop: + push $ddd + push $bootstrap_block + push R3 + push 3 + call $_load_bootstrap_block + mov ACC, $bootstrap_block + mov ACC, *ACC + jeq $_test_partitions_found, DPTBootPartStructure.ID_CODE + inc R3 + mov ACC, R3 + jle $_test_partitions_not_found, R2 + jmp $_test_partitions_loop + +_test_partitions_found: + mov R10, R3 + mulip R10, DPTStructure.ENTRY_SIZE_B + addip R10, R1 + mov *R4, *R10 + addip R4, 2 + addip R10, 2 + mov *R4, *R10 + mov R9, *R4 + addip R9, DPTBootPartStructure.HEADER_SIZE_B ## TODO: This doesn't take into account integer overflow, since it is a 32-Bit address + mov *R4, R9 + mov RV, R3 + ret +_test_partitions_not_found: + mov *R4, 0xFFFF + addip R4, 2 + mov *R4, 0xFFFF + mov RV, 0xFF + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_load_bootstrap_block: ## _load_bootstrap_block(DiskDriverData* ddd, (32 Byte*) bootstrap_block, (1 Byte) dpt_entry) + arg R1 ## @Param: ddd + arg R2 ## @Param: bootstrap_block + arg R7 ## @Param: dpt_entry + mov R3, R1 ## Copy $ddd address into R3 + movb *R1, DiskMode.READ ## $ddd.Mode + inc R1 + movb *R1, 0x00 ## $ddd.Disk + inc R1 + mov R10, $dpt_block.Entries + mulip R7, DPTStructure.ENTRY_SIZE_B + addip R10, R7 + mov *R1, *R10 ## $ddd.Sector + addip R1, 2 + addip R10, 2 + mov *R1, *R10 ## $ddd.Address + addip R1, 2 + mov *R1, DPTBootPartStructure.HEADER_SIZE_B ## $ddd.DataSize + addip R1, 2 + mov *R1, R2 ## $ddd.MemoryAddress + mov R9, R3 ## Move original $ddd address into R9 (for int 0x20) + mov R10, 0x12 ## int 0x20 parameter for load_from_ddd_blocking + int 0x20 ## Bios interrupt ret ## ========================================================================================================================= @@ -127,6 +239,60 @@ _load_dpt_block: ## _load_dpt_block(DiskDriverData* ddd, DPTBlock* dpt_block) ret ## ========================================================================================================================= + + + +## ========================================================================================================================= +_print_error_msg: ## _print_error_msg(string* error_msg) + arg R1 ## @Param: error_msg + ## TODO: Clear the screen + movb [$textCell.CoordX], 0 + movb [$textCell.CoordY], 1 + movb [$textCell.Foreground], DefaultPalette.Red + movb [$textCell.Background], DefaultPalette.Black + mov R10, 0x22 + mov R8, R1 + mov R9, $textCell + int 0x30 + ret +## ========================================================================================================================= + + + + +## ========================================================================================================================= +_print_system_info: + movb [$textCell.CoordX], 0 + movb [$textCell.CoordY], 0 + movb [$textCell.Foreground], DefaultPalette.Green + movb [$textCell.Background], DefaultPalette.Black + mov R10, 0x22 + mov R8, $drake_version_str + mov R9, $textCell + int 0x30 + movb [$textCell.CoordX], 13 + mov R10, 0x22 + mov R8, $dpt_version_str + mov R9, $textCell + int 0x30 + movb [$textCell.CoordX], 26 + mov R10, 0x23 + movb R8, [{ $dpt_block + 2 }] + mov R9, $textCell + int 0x30 + movb [$textCell.CoordX], 27 + movb [$textCell.Character], 0x2E + mov R10, 0x21 + mov R9, $textCell + int 0x30 + movb [$textCell.CoordX], 28 + mov R10, 0x23 + movb R8, [{ $dpt_block + 3 }] + mov R9, $textCell + int 0x30 + ret +## ========================================================================================================================= + ## ========================================================================================================================= @@ -154,151 +320,108 @@ _redraw_screen: ## ========================================================================================================================= -_swap_buffers: - movb [VGA_Registers.SIGNAL], Sig_VGA_Text_16_Color.SWAP_BUFFERS - ret +## _swap_buffers: +## movb [VGA_Registers.SIGNAL], Sig_VGA_Text_16_Color.SWAP_BUFFERS +## ret ## ========================================================================================================================= ## ========================================================================================================================= -_print_main_box: - movb [$textCell.CoordX], 5 - movb [$textCell.CoordY], 2 - movb [$textCell.Foreground], DefaultPalette.Sky - movb [$textCell.Background], DefaultPalette.DarkBlue - movb [$textCell.Character], 0x3D - - mov R8, [CMOS_Settings.SCREEN_WIDTH] - subip R8, 10 - - push $textCell - push R8 - push 2 - call $_draw_horizontal_line - - movb [$textCell.CoordX], 5 - movb [$textCell.CoordY], 12 - push $textCell - push R8 - push 2 - call $_draw_horizontal_line - - movb [$textCell.CoordX], 4 - movb [$textCell.CoordY], 2 - movb [$textCell.Character], 0x7C - push $textCell - push 11 - push 2 - call $_draw_vertical_line - - addip R8, 5 - movb [$textCell.CoordX], R8 - movb [$textCell.CoordY], 2 - push $textCell - push 11 - push 2 - call $_draw_vertical_line - ret +## _key_pressed: +## mov ACC, [Keyboard_Registers.KEYCODE] +## jne $_key_pressed_end, 0x0127 +## _key_pressed_end: +## ret ## ========================================================================================================================= ## ========================================================================================================================= -_draw_horizontal_line: ## _draw_horizontal_line(TextCell16* cell, int8_t length) - arg R1 ## @Param: cell - arg R2 ## @Param: length - mov R3, R1 - addip R3, 3 - movb R4, *R3 - - mov R10, 0x21 - mov R9, R1 -_draw_horizontal_line_loop: - int 0x30 - movb R5, *R3 - inc R5 - movb *R3, R5 - sub R5, R4 - jgr $_draw_horizontal_line_loop, R2 - ret +## _print_main_box: +## movb [$textCell.CoordX], 5 +## movb [$textCell.CoordY], 2 +## movb [$textCell.Foreground], DefaultPalette.Sky +## movb [$textCell.Background], DefaultPalette.DarkBlue +## movb [$textCell.Character], 0x3D +## +## mov R8, [CMOS_Settings.SCREEN_WIDTH] +## subip R8, 10 +## +## push $textCell +## push R8 +## push 2 +## call $_draw_horizontal_line +## +## movb [$textCell.CoordX], 5 +## movb [$textCell.CoordY], 12 +## push $textCell +## push R8 +## push 2 +## call $_draw_horizontal_line +## +## movb [$textCell.CoordX], 4 +## movb [$textCell.CoordY], 2 +## movb [$textCell.Character], 0x7C +## push $textCell +## push 11 +## push 2 +## call $_draw_vertical_line +## +## addip R8, 5 +## movb [$textCell.CoordX], R8 +## movb [$textCell.CoordY], 2 +## push $textCell +## push 11 +## push 2 +## call $_draw_vertical_line +## ret ## ========================================================================================================================= ## ========================================================================================================================= -_draw_vertical_line: ## _draw_line(TextCell16* cell, int8_t length) - arg R1 ## @Param: cell - arg R2 ## @Param: length - mov R3, R1 - addip R3, 4 - movb R4, *R3 - - mov R10, 0x21 - mov R9, R1 -_draw_vertical_line_loop: - int 0x30 - movb R5, *R3 - inc R5 - movb *R3, R5 - sub R5, R4 - jgr $_draw_vertical_line_loop, R2 - ret -## ========================================================================================================================= - - - - -## ========================================================================================================================= -_print_error_msg: ## _print_error_msg(string* error_msg) - arg R1 ## @Param: error_msg - ## TODO: Clear the screen - movb [$textCell.CoordX], 0 - movb [$textCell.CoordY], 0 - movb [$textCell.Foreground], DefaultPalette.Red - movb [$textCell.Background], DefaultPalette.Black - mov R10, 0x22 - mov R8, R1 - mov R9, $textCell - int 0x30 - ret +## _draw_horizontal_line: ## _draw_horizontal_line(TextCell16* cell, int8_t length) +## arg R1 ## @Param: cell +## arg R2 ## @Param: length +## mov R3, R1 +## addip R3, 3 +## movb R4, *R3 +## +## mov R10, 0x21 +## mov R9, R1 +## _draw_horizontal_line_loop: +## int 0x30 +## movb R5, *R3 +## inc R5 +## movb *R3, R5 +## sub R5, R4 +## jgr $_draw_horizontal_line_loop, R2 +## ret ## ========================================================================================================================= ## ========================================================================================================================= -_print_system_info: - movb [$textCell.CoordX], 0 - movb [$textCell.CoordY], 0 - movb [$textCell.Foreground], DefaultPalette.Sky - movb [$textCell.Background], DefaultPalette.DarkBlue - mov R10, 0x22 - mov R8, $drake_version_str - mov R9, $textCell - int 0x30 - movb [$textCell.CoordX], 13 - mov R10, 0x22 - mov R8, $dpt_version_str - mov R9, $textCell - int 0x30 - movb [$textCell.CoordX], 26 - mov R10, 0x23 - movb R8, [{ $dpt_block + 2 }] - mov R9, $textCell - int 0x30 - movb [$textCell.CoordX], 27 - movb [$textCell.Character], 0x2E - mov R10, 0x21 - mov R9, $textCell - int 0x30 - movb [$textCell.CoordX], 28 - mov R10, 0x23 - movb R8, [{ $dpt_block + 3 }] - mov R9, $textCell - int 0x30 - ret +## _draw_vertical_line: ## _draw_line(TextCell16* cell, int8_t length) +## arg R1 ## @Param: cell +## arg R2 ## @Param: length +## mov R3, R1 +## addip R3, 4 +## movb R4, *R3 +## +## mov R10, 0x21 +## mov R9, R1 +## _draw_vertical_line_loop: +## int 0x30 +## movb R5, *R3 +## inc R5 +## movb *R3, R5 +## sub R5, R4 +## jgr $_draw_vertical_line_loop, R2 +## ret ## ========================================================================================================================= \ No newline at end of file diff --git a/extra/info/info b/extra/info/info index 9451bfa..8d475b8 100644 --- a/extra/info/info +++ b/extra/info/info @@ -247,3 +247,14 @@ Unallocated 90 kb 92160 bytes (0x16800) 0x0000.1800 -> 0x0001.7FFF DragonOS 2000 kb 2048000 bytes (0x1F4000) 0x0001.8000 -> 0x0020.BFFF Test Partition 2000 kb 2048000 bytes (0x1F4000) 0x0020.C000 -> 0x0040.0000 + + + +#========================================================================================================================================== +# Bootstrap structure +#========================================================================================================================================== + Starting bytes of bootable partition: + Identifier (2 Bytes) - Must be set to 0xF1C4 + Reserved (30 Bytes) + + Kernel first stage block must start at PART_ADDR + 32 and must be 1024 bytes in size \ No newline at end of file diff --git a/extra/make_and_debug b/extra/make_and_debug index 8222b28..e0bcd57 100755 --- a/extra/make_and_debug +++ b/extra/make_and_debug @@ -16,6 +16,7 @@ if [ $? -eq 0 ]; then /bin/bash ./bios_flash cp ../dss/bios_api.dss ../../extra/dss/bios_api.dss /bin/bash ./build_drake + /bin/bash ./build_dragonos cd .. printf "\n${green}Running Application...\n\n${clear}" ./ddb config/testMachine.dvm --verbose-load diff --git a/extra/make_and_run b/extra/make_and_run index 3a0844a..7c1aba7 100755 --- a/extra/make_and_run +++ b/extra/make_and_run @@ -16,6 +16,7 @@ if [ $? -eq 0 ]; then /bin/bash ./bios_flash cp ../dss/bios_api.dss ../../extra/dss/bios_api.dss /bin/bash ./build_drake + /bin/bash ./build_dragonos cd .. printf "\n${green}Running Application...\n\n${clear}" ./dvm config/testMachine.dvm diff --git a/extra/scripts/build_dragonos b/extra/scripts/build_dragonos new file mode 100644 index 0000000..62114ac --- /dev/null +++ b/extra/scripts/build_dragonos @@ -0,0 +1,18 @@ +#!/bin/bash + +green='\033[0;32m' +clear='\033[0m' + +printf "\n${green}Compiling DragonOS...\n${clear}" +cd .. +cp ../extra/dss/DragonOS/* ./dss/DragonOS/ + +printf "\n${green}1) kernel0.dss\n${clear}" +./dasm dss/DragonOS/kernel0.dss -o dragon/kernel0.bin -D +./dtools load-binary dragon/disk1.dr dragon/kernel0.bin 0x00018000 + +printf "\n" + + +cp dragon/disk1.dr ../extra/dragon/disk1.dr +rm dragon/kernel0.bin diff --git a/src/assembler/Assembler.cpp b/src/assembler/Assembler.cpp index 08c4202..7c7fd19 100644 --- a/src/assembler/Assembler.cpp +++ b/src/assembler/Assembler.cpp @@ -57,6 +57,7 @@ namespace dragon for (int16_t i = m_code.size(); i < m_fixedSize; i++) m_code.push_back(m_fixedFillValue); } + insertHeader(); return m_code; } @@ -156,6 +157,32 @@ namespace dragon } + + void Assembler::insertHeader(void) + { + if (m_code.size() == 0) return; + ostd::ByteStream header; + + m_headerStr.toLower().trim(); + if (m_headerStr == "") return; + //TODO: Expand header functionality to allow for custom values maybe + if (m_headerStr == "kernel0_boot") + { + header.push_back((uint8_t)((data::DPTStructure::BootPart_ID_CODE & 0xFF00) >> 8)); + header.push_back((uint8_t)(data::DPTStructure::BootPart_ID_CODE & 0x00FF)); + for (int32_t i = 0; i < 30; i++) + header.push_back(0xFF); + } + else + { + std::cout << "Invalid .header value: " << m_headerStr << "\n"; + return; + } + + m_code.insert(m_code.begin(), header.begin(), header.end()); + } + + void Assembler::removeComments(void) { @@ -800,6 +827,18 @@ namespace dragon m_entry_lbl = lineEdit; continue; } + else if (lineEdit.startsWith(".header ")) + { + if (lineEdit.len() < 9) + { + //TODO: Error + std::cout << "Invalid .header value: " << lineEdit << "\n"; + return; + } + lineEdit.substr(8).trim(); + m_headerStr = lineEdit; + continue; + } else if (lineEdit.startsWith(".load ")) { if (lineEdit.len() < 7) diff --git a/src/assembler/Assembler.hpp b/src/assembler/Assembler.hpp index 233450d..8a1c3f6 100644 --- a/src/assembler/Assembler.hpp +++ b/src/assembler/Assembler.hpp @@ -118,6 +118,8 @@ namespace dragon static void printProgramInfo(void); private: + static void insertHeader(void); + static void removeComments(void); static void replaceDefines(void); static void replaceGroupDefines(void); @@ -163,6 +165,7 @@ namespace dragon inline static uint16_t m_dataSize { 0x0000 }; inline static uint16_t m_programSize { 0x0000 }; inline static ostd::String m_entry_lbl { "" }; + inline static ostd::String m_headerStr { "" }; inline static std::vector m_structDefs; inline static std::vector m_disassembly; diff --git a/src/gui/Window.hpp b/src/gui/Window.hpp index b6d91fb..e68ec28 100644 --- a/src/gui/Window.hpp +++ b/src/gui/Window.hpp @@ -28,8 +28,9 @@ namespace dragon inline bool isInitialized(void) const { return m_initialized; } inline bool isRunning(void) const { return m_running; } - inline void hide(void) { SDL_HideWindow(m_window); } - inline void show(void) { SDL_ShowWindow(m_window); } + inline bool isVisible(void) const { return m_visible; } + inline void hide(void) { SDL_HideWindow(m_window); m_visible = false; } + inline void show(void) { SDL_ShowWindow(m_window); m_visible = true; } inline ostd::String getTitle(void) const { return m_title; } inline int32_t getFPS(void) const { return m_fps; } inline int32_t getWindowWidth(void) const { return m_windowWidth; } @@ -63,6 +64,7 @@ namespace dragon bool m_deagEventEnabled { false }; bool m_running { false }; bool m_initialized { false }; + bool m_visible { true }; }; class WindowResizedData : public ostd::BaseObject { diff --git a/src/hardware/VirtualDisplay.cpp b/src/hardware/VirtualDisplay.cpp index 23974f3..c584bf0 100644 --- a/src/hardware/VirtualDisplay.cpp +++ b/src/hardware/VirtualDisplay.cpp @@ -26,6 +26,7 @@ namespace dragon void VirtualDisplay::onRender(void) { + if (!isVisible()) return; auto& config = DragonRuntime::machine_config; auto& mem = DragonRuntime::memMap; uint16_t vga_addr = data::MemoryMapAddresses::VideoCardInterface_Start; diff --git a/src/tools/GlobalData.hpp b/src/tools/GlobalData.hpp index 31a82d7..508560e 100644 --- a/src/tools/GlobalData.hpp +++ b/src/tools/GlobalData.hpp @@ -234,32 +234,40 @@ namespace dragon }; public: - inline static constexpr uint16_t DPTID = 0x000; - inline static constexpr uint16_t DPTVersionMaj = 0x002; - inline static constexpr uint16_t DPTVersionMin = 0x003; - inline static constexpr uint16_t PartitionCount = 0x004; + inline static constexpr uint16_t DPTID = 0x000; + inline static constexpr uint16_t DPTVersionMaj = 0x002; + inline static constexpr uint16_t DPTVersionMin = 0x003; + inline static constexpr uint16_t PartitionCount = 0x004; - inline static constexpr uint16_t EntriesStart = 0x00C; + inline static constexpr uint16_t EntriesStart = 0x00C; - inline static constexpr uint16_t EntryStartAddress = 0x000; - inline static constexpr uint16_t EntryPartitionSize = 0x004; - inline static constexpr uint16_t EntryFlags = 0x008; - inline static constexpr uint16_t EntryPartitionLabel = 0x024; + inline static constexpr uint16_t EntryStartAddress = 0x000; + inline static constexpr uint16_t EntryPartitionSize = 0x004; + inline static constexpr uint16_t EntryFlags = 0x008; + inline static constexpr uint16_t EntryPartitionLabel = 0x024; - inline static constexpr uint16_t HeaderReservedSizeBytes= 7; - inline static constexpr uint16_t DiskAddress = 0x200; - inline static constexpr uint16_t DPT_ID_CODE = 0xF1CA; - inline static constexpr uint16_t EntrySizeBytes = 100; - inline static constexpr uint16_t EntryLabelSizeBytes = 64; - inline static constexpr uint16_t EntryReservedSizeBytes = 26; - inline static constexpr uint16_t HeaderSizeBytes = 12; - inline static constexpr uint16_t DPTBlockSizeBytes = 512; - inline static constexpr uint8_t CurrentDPTVersionMaj = 0x00; - inline static constexpr uint8_t CurrentDPTVersionMin = 0x02; - inline static constexpr uint32_t DiskStartAddr = 0x00000400; - inline static constexpr uint8_t MaxPartCount = 5; + inline static constexpr uint16_t HeaderReservedSizeBytes = 7; + inline static constexpr uint16_t DiskAddress = 0x200; + inline static constexpr uint16_t DPT_ID_CODE = 0xF1CA; + inline static constexpr uint16_t EntrySizeBytes = 100; + inline static constexpr uint16_t EntryLabelSizeBytes = 64; + inline static constexpr uint16_t EntryReservedSizeBytes = 26; + inline static constexpr uint16_t HeaderSizeBytes = 12; + inline static constexpr uint16_t DPTBlockSizeBytes = 512; + inline static constexpr uint8_t CurrentDPTVersionMaj = 0x00; + inline static constexpr uint8_t CurrentDPTVersionMin = 0x02; + inline static constexpr uint32_t DiskStartAddr = 0x00000400; + inline static constexpr uint8_t MaxPartCount = 5; + + + + inline static constexpr uint16_t BootPart_IDAddr = 0x0000; + inline static constexpr uint16_t BootPart_CodeStart = 0x0020; + inline static constexpr uint16_t BootPart_ID_CODE = 0xF1C4; + inline static constexpr uint16_t BootPart_CodeSizeBytes = 1024; + inline static constexpr uint8_t BootPart_HeaderSizeBytes = 32; }; class CPUExtension