Skip to content

Commit

Permalink
fixed a lot of stuff (bochs works again)
Browse files Browse the repository at this point in the history
  • Loading branch information
F1L1Pv2 committed Mar 20, 2024
1 parent 89762d5 commit 0b70fa2
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 82 deletions.
2 changes: 1 addition & 1 deletion debug.bat
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@echo off
wsl make
wsl rm "build/bios-htc.img.lock"
wsl rm "build/modex.img.lock"
bochsdbg -q -f .\bochs_config
116 changes: 58 additions & 58 deletions src/bootloader/boot_io.asm
Original file line number Diff line number Diff line change
Expand Up @@ -152,67 +152,67 @@ ScreenBuffer equ 0xB8000

; ret

; binary_hexadecimal:
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;; funkcja binary to decimal (16-bits) ;;
; ;; AX to wejsce ;;
; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
binary_hexadecimal:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; funkcja binary to decimal (16-bits) ;;
;; AX to wejsce ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

; push edx
; push ecx
; push ebx
; push eax
push edx
push ecx
push ebx
push eax

; xor ebx, ebx
xor ebx, ebx

; .loop:
; xor edx, edx
; mov ecx, 16
; div ecx
; mov ecx, eax

; mov al, dl
; cmp al, 10
; jge .letter
; .number:
; add al, '0'
; jmp .after
; .letter:
; add al, 'A' - 10
; .after:
; push eax

; mov eax, ecx

; inc ebx

; test ecx, ecx
; jnz .loop

; mov ah, GLOBAL_COLOR
; mov al, '0'
; call write_char
; inc word [cursor]
; mov al, 'x'
; call write_char
; inc word [cursor]

; .flip:
; pop eax
; mov ah, GLOBAL_COLOR
; call write_char
; inc word [cursor]

; dec ebx
; jnz .flip

; pop eax
; pop ebx
; pop ecx
; pop edx

; call update_cursor
; ret
.loop:
xor edx, edx
mov ecx, 16
div ecx
mov ecx, eax

mov al, dl
cmp al, 10
jge .letter
.number:
add al, '0'
jmp .after
.letter:
add al, 'A' - 10
.after:
push eax

mov eax, ecx

inc ebx

test ecx, ecx
jnz .loop

mov ah, GLOBAL_COLOR
mov al, '0'
call write_char
inc word [cursor]
mov al, 'x'
call write_char
inc word [cursor]

.flip:
pop eax
mov ah, GLOBAL_COLOR
call write_char
inc word [cursor]

dec ebx
jnz .flip

pop eax
pop ebx
pop ecx
pop edx

call update_cursor
ret

new_line:
;;F1L1P;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
3 changes: 2 additions & 1 deletion src/bootloader_drivers/ata.asm
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ ata_read_sectors:
cmp ebx, 256
jl .loop

call wait_400ns

dec ecx
cmp ecx, 0
jne .call_next_sector
Expand All @@ -152,7 +154,6 @@ ata_read_sectors:


.after_loop:
call wait_400ns

pop esi
pop edi
Expand Down
42 changes: 30 additions & 12 deletions src/bootloader_drivers/fat16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,34 @@ fat_load_and_update_cluster:
call claculate_first_sector_of_cluster

mov edi, eax
xor edx, edx
mov dl, byte [bdb_sectors_per_cluster]
mov cl, byte [bdb_sectors_per_cluster]
mov dl, 1

;; TODO: for some reason ata doesnt work good if it needs to load more than 1 sector so for now im manually loading one sector at a time

.load_loop:
cmp cl, 0
je .after

call ata_read_sectors
xor eax, eax
mov al, byte [bdb_sectors_per_cluster]
xor ecx, ecx
mov cx, word [bdb_bytes_per_sector]
xor edx, edx
mul ecx
add esi, eax

dec cl
inc edi
add esi, 512
jmp .load_loop
.after:

; mov edi, eax
; xor edx, edx
; mov dl, byte [bdb_sectors_per_cluster]
; call ata_read_sectors
; xor eax, eax
; mov al, byte [bdb_sectors_per_cluster]
; xor ecx, ecx
; mov cx, word [bdb_bytes_per_sector]
; xor edx, edx
; mul ecx
; add esi, eax

pop ecx
pop edx
Expand Down Expand Up @@ -138,6 +156,7 @@ fat_load_file_root_dir:
cmp bx, word [bdb_root_entry_count]
jl .search_kernel_loop

; clearing zero flag for failure
mov eax, 1
cmp eax, 0
jmp .after
Expand All @@ -146,6 +165,7 @@ fat_load_file_root_dir:
; call panic

.kernel_found:

mov esi, edi
mov eax, dword [esi+28]
mov dword [kernel_size_in_bytes], eax
Expand All @@ -161,15 +181,13 @@ fat_load_file_root_dir:
call ata_read_sectors

mov esi, dword [fat_imm_load_offset]
; mov esi, KERNEL_LOAD_OFFSET
; mov edx, 0
.fat_load_loop:
inc edx
call fat_load_and_update_cluster
call fat_get_next_cluster
cmp eax, 0xFFF8
jl .fat_load_loop

; setting zero flag for success
mov eax, 0
cmp eax, 0
.after:
Expand Down
3 changes: 0 additions & 3 deletions src/kernel/core/io.asm
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,6 @@ print_bcd:

cursor: dd 0

vga_history: times 10*80*25 db 0
vga_history_len equ $ - vga_history

read_content: times read_content_len db 0
db 0 ; padding
read_cursor: dw 0
18 changes: 13 additions & 5 deletions src/kernel/core/memory.asm
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use32

memmory_between_msg: db " | ",0

Expand Down Expand Up @@ -312,7 +313,6 @@ setup_physical_alloc:
call round_up
mov dword [membit_table_size_bytes], eax


;calculate how much kernel uses pages
mov eax, dword [kernel_size_in_bytes]
mov edx, 0
Expand All @@ -333,6 +333,17 @@ setup_physical_alloc:
;allocate initial pages
xor edx, edx
mov eax, dword [initial_allocated_pages]
cmp eax, 8
jge .more_than_byte

.less_than_byte:
mov al, dl
call fill_bits
mov [memmory_bit_map], al
jmp .exit


.more_than_byte:
mov ecx, 8
div ecx
push edx
Expand All @@ -347,7 +358,6 @@ setup_physical_alloc:
mov eax, edx
call fill_bits
mov byte [esi], al

.exit:
pop ecx
pop edx
Expand Down Expand Up @@ -474,6 +484,4 @@ max_page_count: dd 0
page_table_size: dd 0
kernel_use_page_count: dd 0
membit_table_size_bytes: dd 0
initial_allocated_pages: dd 0

pages_bitmap: times 131072 db 0
initial_allocated_pages: dd 0
4 changes: 2 additions & 2 deletions src/kernel/main.asm
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ run_command:

.love_command:
; call cls
call valentine
; call valentine
call new_line
jmp .after
.after:
Expand Down Expand Up @@ -357,7 +357,7 @@ panic:
panic_msg: db "KERNEL PANIC: ", 0

; Include core and drivers!
include "../eastereggs/valentine.asm"
; include "../eastereggs/valentine.asm"
include "core/initial_tools.asm"
include "src/drivers/ps2_keyboard.asm"
include "src/drivers/filesys.asm"
Expand Down

0 comments on commit 0b70fa2

Please sign in to comment.