chore: sync repo

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-23 07:50:35 +02:00
parent 593e8a2b9c
commit 008c7800f4
4 changed files with 85 additions and 8 deletions

View file

@ -37,6 +37,7 @@ SRCS = kernel.asm \
fs/xv6fs.inc \ fs/xv6fs.inc \
vfs.inc \ vfs.inc \
proc.inc \ proc.inc \
bio.inc \
$(ASMINCS) $(ASMINCS)
.PHONY: all .PHONY: all

33
kernel/bio.inc Normal file
View file

@ -0,0 +1,33 @@
;; File: bio.inc
;; Buffer cache
;; Struc: Buffer
struc Buffer {
.dev dd ?
.block dd ?
.ulock dd ?
.refcount dd ?
.data db 512 dup(?)
}
DEFN Buffer
;; Function: bio_init
bio_init:
mov ecx, sizeof.Buffer * 30
xor ax, ax
mov edi, aBuffers
rep stosb
ret
bio_get:
mov eax, uBIOLock
call lock_acquire
mov eax, uBIOLock
call lock_release
ret
bio_brelse:
ret
uBIOLock dd 0

View file

@ -1,7 +1,8 @@
;; File: ata.inc ;; File: ata.inc
;; ;;
;; <ATA PIO Mode at https://wiki.osdev.org/ATA_PIO_Mode> ;; Usefull links:
;; <IDE spec at https://www.cpcwiki.eu/imgs/a/a2/IDE_SPEC.PDF> ;; - <ATA PIO Mode at https://wiki.osdev.org/ATA_PIO_Mode>
;; - <IDE spec at https://www.cpcwiki.eu/imgs/a/a2/IDE_SPEC.PDF>
ATA_PRIMARY_IO = 0x1F0 ATA_PRIMARY_IO = 0x1F0
ATA_PRIMARY_IO_CTRL = 0x3F6 ATA_PRIMARY_IO_CTRL = 0x3F6
@ -76,10 +77,21 @@ ATA_CMD_IDENTIFY = 0xA0
ata_wait: ata_wait:
mov dx, ax mov dx, ax
add dx, ATA_STATUS add dx, ATA_STATUS
xor ecx, ecx
@@: @@:
inc ecx
cmp ecx, 5000
jg @f
in al, dx in al, dx
and al, ATA_STATUS_BSY and al, ATA_STATUS_BSY
jnz @b jnz @b
@@:
ret
ata_select:
ret
ata_cmd:
ret ret
;; Function: ata_probe ;; Function: ata_probe
@ -102,7 +114,9 @@ ata_probe:
out dx, al out dx, al
mov ax, bx mov ax, bx
push ecx
call ata_wait call ata_wait
pop ecx
mov dx, bx mov dx, bx
add dx, ATA_COMMAND add dx, ATA_COMMAND
@ -110,16 +124,20 @@ ata_probe:
out dx, al out dx, al
mov ax, bx mov ax, bx
push ecx
call ata_wait call ata_wait
pop ecx
mov dx, bx mov dx, bx
add dx, ATA_STATUS add dx, ATA_STATUS
in al, dx in al, dx
and al, ATA_STATUS_ERR or ATA_STATUS_DRQ and al, ATA_STATUS_ERR or ATA_STATUS_DRQ
jnz @f jnz .skip
mov ax, bx mov ax, bx
push ecx
call ata_wait call ata_wait
pop ecx
mov dx, bx mov dx, bx
add dx, ATA_COMMAND add dx, ATA_COMMAND
@ -127,20 +145,39 @@ ata_probe:
out dx, al out dx, al
mov ax, bx mov ax, bx
push ecx
call ata_wait call ata_wait
pop ecx
mov dx, bx mov dx, bx
add dx, ATA_STATUS add dx, ATA_STATUS
in al, dx in al, dx
and al, ATA_STATUS_ERR or ATA_STATUS_DRQ and al, ATA_STATUS_ERR or ATA_STATUS_DRQ
jnz @f jnz .skip
push ecx push ecx
cmp ecx, ATA_CHAN1_IO
jne @f
add ecx, 2
jmp .drive_found
@@:
cmp ecx, ATA_CHAN2_IO
jne @f
add ecx, 4
jmp .drive_found
@@:
cmp ecx, ATA_CHAN3_IO
jne @f
add ecx, 8
jmp .drive_found
@@:
.drive_found:
push ecx push ecx
mov esi, szMsgAtaFound mov esi, szMsgAtaFound
call klog call klog
pop ecx pop ecx
@@: .skip:
inc cl inc cl
cmp cl, 2 cmp cl, 2
jb .loop jb .loop
@ -172,9 +209,9 @@ ata_device:
aAtaChans: aAtaChans:
dw ATA_CHAN0_IO dw ATA_CHAN0_IO
; dw ATA_CHAN1_IO dw ATA_CHAN1_IO
; dw ATA_CHAN2_IO dw ATA_CHAN2_IO
; dw ATA_CHAN3_IO dw ATA_CHAN3_IO
.end: .end:
szMsgAtaFound db "ATA: hd%u found", 0 szMsgAtaFound db "ATA: hd%u found", 0

View file

@ -79,6 +79,8 @@ kmain:
call pit_init call pit_init
call bio_init
call proc_init call proc_init
call dev_init call dev_init
@ -116,6 +118,7 @@ kmain:
include 'fs/stpdfs.inc' include 'fs/stpdfs.inc'
include 'fs/xv6fs.inc' include 'fs/xv6fs.inc'
include 'proc.inc' include 'proc.inc'
include 'bio.inc'
szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0 szMsgKernelAlive db "Kernel (", VERSION_FULL , ") is alive", 0
@ -126,7 +129,10 @@ boot_structure BootInfo
kTSS TSS kTSS TSS
align 4096
aProcs rb 64*sizeof.Process aProcs rb 64*sizeof.Process
align 4096
aBuffers rb 30*sizeof.Buffer
align 4096 align 4096
stack_bottom: stack_bottom: