feat(kernel): probe ne2k

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-07-22 17:31:24 +02:00
parent 40e16ca551
commit e84e98f6a5
5 changed files with 109 additions and 63 deletions

View file

@ -28,6 +28,7 @@ SRCS = kernel.asm \
dev/at/cga.inc \
dev/at/kbd.inc \
dev/at/com.inc \
dev/at/ne2k.inc \
dev/at/floppy.inc \
dev/dev.inc \
fs/fat.inc \

View file

@ -4,63 +4,67 @@
;; - <datasheet at https://web.archive.org/web/20010612150713/http://www.national.com/ds/DP/DP8390D.pdf>
NE2K_IOBASE = 0x300
NE2K_ASIC = NE2K_IOBASE + 0x10
NE2K_NIC = NE2K_IOBASE + 0x00
NE2K_RESET = 0xF
; PAGE 0
NE2K_CR = NE2K_IOBASE + 0x0
DP8390D_CR = 0x0
NE2K_CR_PS1 = 0x80
NE2K_CR_PS0 = 0x40
NE2K_CR_RD2 = 0x20
NE2K_CR_RD1 = 0x10
NE2K_CR_RD0 = 0x08
NE2K_CR_TXP = 0x04
NE2K_CR_STA = 0x02
NE2K_CR_STP = 0x01
DP8390D_CR_PS1 = 0x80
DP8390D_CR_PS0 = 0x40
DP8390D_CR_RD2 = 0x20
DP8390D_CR_RD1 = 0x10
DP8390D_CR_RD0 = 0x08
DP8390D_CR_TXP = 0x04
DP8390D_CR_STA = 0x02
DP8390D_CR_STP = 0x01
NE2K_CLDA0 = NE2K_IOBASE + 0x1
NE2K_CLDA1 = NE2K_IOBASE + 0x2
NE2K_BNRY = NE2K_IOBASE + 0x3
NE2K_TSR = NE2K_IOBASE + 0x4
NE2K_NCR = NE2K_IOBASE + 0x5
NE2K_FIFO = NE2K_IOBASE + 0x6
NE2K_ISR = NE2K_IOBASE + 0x7
NE2K_CRDA0 = NE2K_IOBASE + 0x8
NE2K_CRDA1 = NE2K_IOBASE + 0x9
NE2K_RSR = NE2K_IOBASE + 0xC
NE2K_CNTR0 = NE2K_IOBASE + 0xD
NE2K_CNTR1 = NE2K_IOBASE + 0xE
NE2K_CNTR2 = NE2K_IOBASE + 0xF
DP8390D_CLDA0 = 0x1
DP8390D_CLDA1 = 0x2
DP8390D_BNRY = 0x3
DP8390D_TSR = 0x4
DP8390D_NCR = 0x5
DP8390D_FIFO = 0x6
DP8390D_ISR = 0x7
DP8390D_CRDA0 = 0x8
DP8390D_CRDA1 = 0x9
DP8390D_RSR = 0xC
DP8390D_CNTR0 = 0xD
DP8390D_CNTR1 = 0xE
DP8390D_CNTR2 = 0xF
NE2K_PSTART = NE2K_IOBASE + 0x1
NE2K_PSTOP = NE2K_IOBASE + 0x2
NE2K_TPSR = NE2K_IOBASE + 0x4
NE2K_TBCR0 = NE2K_IOBASE + 0x5
NE2K_TBCR1 = NE2K_IOBASE + 0x6
NE2K_RSAR0 = NE2K_IOBASE + 0x8
NE2K_RSAR1 = NE2K_IOBASE + 0x9
NE2K_RBCR0 = NE2K_IOBASE + 0xA
NE2K_RBCR1 = NE2K_IOBASE + 0xB
NE2K_RCR = NE2K_IOBASE + 0xC
NE2K_TCR = NE2K_IOBASE + 0xD
NE2K_DCR = NE2K_IOBASE + 0xE
NE2K_IMR = NE2K_IOBASE + 0xF
DP8390D_PSTART = 0x1
DP8390D_PSTOP = 0x2
DP8390D_TPSR = 0x4
DP8390D_TBCR0 = 0x5
DP8390D_TBCR1 = 0x6
DP8390D_RSAR0 = 0x8
DP8390D_RSAR1 = 0x9
DP8390D_RBCR0 = 0xA
DP8390D_RBCR1 = 0xB
DP8390D_RCR = 0xC
DP8390D_TCR = 0xD
DP8390D_DCR = 0xE
DP8390D_IMR = 0xF
; PAGE 1
NE2K_PAR0 = NE2K_IOBASE + 0x1
NE2K_PAR1 = NE2K_IOBASE + 0x2
NE2K_PAR2 = NE2K_IOBASE + 0x3
NE2K_PAR3 = NE2K_IOBASE + 0x4
NE2K_PAR4 = NE2K_IOBASE + 0x5
NE2K_PAR5 = NE2K_IOBASE + 0x6
NE2K_CURR = NE2K_IOBASE + 0x7
NE2K_MAR0 = NE2K_IOBASE + 0x8
NE2K_MAR1 = NE2K_IOBASE + 0x9
NE2K_MAR2 = NE2K_IOBASE + 0xA
NE2K_MAR3 = NE2K_IOBASE + 0xB
NE2K_MAR4 = NE2K_IOBASE + 0xC
NE2K_MAR5 = NE2K_IOBASE + 0xD
NE2K_MAR6 = NE2K_IOBASE + 0xE
NE2K_MAR7 = NE2K_IOBASE + 0xF
DP8390D_PAR0 = 0x1
DP8390D_PAR1 = 0x2
DP8390D_PAR2 = 0x3
DP8390D_PAR3 = 0x4
DP8390D_PAR4 = 0x5
DP8390D_PAR5 = 0x6
DP8390D_CURR = 0x7
DP8390D_MAR0 = 0x8
DP8390D_MAR1 = 0x9
DP8390D_MAR2 = 0xA
DP8390D_MAR3 = 0xB
DP8390D_MAR4 = 0xC
DP8390D_MAR5 = 0xD
DP8390D_MAR6 = 0xE
DP8390D_MAR7 = 0xF
ne2k_init:
call ne2k_probe
@ -68,22 +72,37 @@ ne2k_init:
jnz @f
mov esi, szMsgNe2kfound
call klog
mov dx, NE2K_IOBASE
in al, dx
out dx, al
mov al, NE2K_CR_STP
out dx, al
@@:
@@:
ret
ne2k_probe:
mov dx, NE2K_IOBASE + NE2K_CR
mov dx, NE2K_ASIC + NE2K_RESET
in al, dx
and al, 0x27
cmp al, 0x21
out dx, al
mov ecx, 5000
@@:
dec ecx
or ecx, ecx
jnz @b
mov dx, NE2K_NIC + DP8390D_CR
mov al, DP8390D_CR_RD2 or DP8390D_CR_STP
out dx, al
mov ecx, 5000
@@:
dec ecx
or ecx, ecx
jnz @b
mov dx, NE2K_NIC + DP8390D_CR
in al, dx
and al, (DP8390D_CR_RD2 or DP8390D_CR_TXP or DP8390D_CR_STA or DP8390D_CR_STP)
cmp al, (DP8390D_CR_RD2 or DP8390D_CR_STP)
jne @f
xor eax, eax
@@:
ret

View file

@ -144,6 +144,7 @@ mm_clone_pgdir:
ret
;; Function: mm_init
;; Initialize the memory manager
mm_init:
mov esi, szMsgMmInit
call klog
@ -189,10 +190,23 @@ mm_init:
ret
mm_alloc:
;; Function: mm_mmap
;;
;; In:
;; XXX - addr
;; XXX - length
;; XXX - prot
;; XXX - flags
mm_mmap:
ret
mm_dealloc:
;; Function: mm_munmap
;;
;; In:
;; XXX - addr
;; XXX - length
;;
mm_munmap:
ret
mm_wallk_pagedir:

View file

@ -24,6 +24,7 @@ proc_alloc:
mov eax, -1
jmp .end
@@:
.end:
push eax
mov eax, uProcLock
@ -31,7 +32,7 @@ proc_alloc:
pop eax
ret
uNextpid dd 1
uProcLock dd 0
pCurrentProc dd 0
szErrorNoFreeProcess db "Error: can't alloc new process", 0

View file

@ -3,10 +3,21 @@ SYSCALL_FORK = 0x02
SYSCALL_READ = 0x03
SYSCALL_WRITE = 0x04
syscall_null:
ret
isr_syscall:
push eax
mov esi, szMsgSyscall
call klog
iret
szMsgSyscall db "syscall %x", 0
apSyscallTable:
dd syscall_null ; SYSCALL_NULL
dd 0 ; SYSCALL_EXIT
dd 0 ; SYSCALL_FORK
dd 0 ; SYSCALL_READ
dd 0 ; SYSCALL_WRITE