Conversation
|
Hmm looks like there are some issues with RISC-V |
include/tilck/kernel/modules.h
Outdated
| #define MOD_serial_prio 400 | ||
| #define MOD_sb16_prio 410 | ||
| #define MOD_null_prio 420 | ||
| #define MOD_e1000_prio 430 // TODO: check that this is right |
| @@ -0,0 +1,23 @@ | |||
|
|
|||
There was a problem hiding this comment.
Missing:
/* SPDX-License-Identifier: BSD-2-Clause */
|
|
||
| void kcond_init(struct kcond *c); | ||
| void kcond_destory(struct kcond *c); | ||
| void kcond_destroy(struct kcond *c); |
There was a problem hiding this comment.
Thanks for noticing this typo! I don't know how it survived so long unnoticed!
include/tilck/kernel/sys_types.h
Outdated
| #include <sys/utsname.h> // system header | ||
| #include <sys/stat.h> // system header | ||
| #include <fcntl.h> // system header | ||
| #include <arpa/inet.h> |
There was a problem hiding this comment.
Missing // system header comment
kernel/arch/generic_x86/pic.c
Outdated
| outb(PIC2_IMR, ICW4_8086); | ||
| pic_io_wait(); | ||
|
|
||
| outb(PIC1_IMR, 0xff); |
There was a problem hiding this comment.
Can you clarify why do we need that?
There was a problem hiding this comment.
The changes in pic.c are redundant. I was having troubles getting the IRQ handler to fire, so I added these lines to ensure the PIC was letting IRQs through. I'll restore it as it was before
modules/e1000/e1000.c
Outdated
| printk("e1000: Sending frame len=%d\n", len); | ||
|
|
||
| /* Number of descriptors that would be required to send this message. */ | ||
| u32 num_desc = CEIL((u32) len, TX_BUF_SIZE); |
There was a problem hiding this comment.
If len was unsigned we wouldn't need those casts.
modules/e1000/e1000.c
Outdated
| /* | ||
| * Slow path. Packet spans multiple entries. Not implemented yet. | ||
| */ | ||
| ASSERT(0); |
There was a problem hiding this comment.
Is NOT_IMPLEMENTED() more appropriate here?
|
|
||
| void *src = PA_TO_KERNEL_VA(rx_ring[rx_tail].addr); | ||
| size_t len = rx_ring[rx_tail].length; | ||
|
|
modules/e1000/e1000.c
Outdated
| */ | ||
|
|
||
| void *src = PA_TO_KERNEL_VA(rx_ring[rx_tail].addr); | ||
| size_t len = rx_ring[rx_tail].length; |
There was a problem hiding this comment.
You're using size_t while length is u16. Why not using everywhere u32 (except in the struct, of course).
| -gdb tcp::$GDB_PORT \ | ||
| @QEMU_RAM_OPT@ \ | ||
| -drive id=img1,format=raw,if=none,file=@IMG_FILE@ \ | ||
| -netdev user,id=net0,hostfwd=udp::2222-:22 \ |
There was a problem hiding this comment.
If you add this to the QEMU scripts, you should make the e1000 module disabled by default as it's in-development at the moment. You can do this by adding it to this list:
list(
APPEND disabled_modules_list
# No modules in this list, at the moment
)
In the main CMakeLists.txt file. If something is not mature enough, shouldn't be enabled by default.
There was a problem hiding this comment.
Just curious, why is adding the netdev to qemu related to disabling the module by default?
Also, what is the normal way to enable it without modifying the CMakeLists.txt?
|
Thanks for the review! I'll go through it in the next couple days |
|
In kernel mode we don't use `size_t` as much as in userspace. size_t is the
goto/nobrainer type for "size" in userspace. In the kernel, usually, we try
to use the more efficient type for the purpose. Even on x86-64, 64-bit
operations are a bit more expensive than 32-bit ones, due to the need for
the REX.W prefix. When interacting with HW buffers almost where we operate
with multi GB buffers. So, u32 is already big enough. Notice the
length field in the struct is 32 bit, anyway.
So, yeah, in summary, the rule of the thumb is to use u32 by default for
unsigned types, unless there's a serious use-case for 64 bit, like file
sizes and offsets. For memory addresses, we should use the variable size
`long` / `ulong`.
…On Mon, Mar 30, 2026 at 1:38 AM Francesco Cozzuto ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In modules/e1000/e1000.c
<#241?email_source=notifications&email_token=AALYOLCOWCELQY7ILR26UOL4TIW7TA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBSHA4TKNBZGQ3KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJL3QOJPXEZLWNFSXOX3DNRUWG2Y#discussion_r3008353501>
:
> +}
+
+static void write_reg(u32 off, u32 val)
+{
+ if (is_mmio) {
+ *(volatile u32*) (io_addr + off) = val;
+ } else {
+ outl(io_addr + 0x0, off);
+ outl(io_addr + 0x4, val);
+ }
+}
+
+/*
+ * Send packet
+ */
+static int e1000_send(char *src, int len)
I default to signed types to catch overflows with ubsan, but using an
unsigned field here is okay. Should it be an u32 or size_t? I think the
latter is more appropriate for a number of bytes
—
Reply to this email directly, view it on GitHub
<#241?email_source=notifications&email_token=AALYOLBL36VKIWSWHK6GHST4TIW7TA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBSHA4TKNBZGQ3KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJPLQOJPXEZLWNFSXOX3ON52GSZTJMNQXI2LPNZZV6Y3MNFRWW#discussion_r3008353501>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALYOLCJ3SCZDQSGLJTQPYD4TIW7TAVCNFSM6AAAAACXAE5OJ2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DAMRYHE2TIOJUGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
|
I'm sure you can find it. I think it was something like string_util.h, but
I cannot access the code at the moment to check.
…On Mon, Mar 30, 2026 at 1:39 AM Francesco Cozzuto ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In modules/e1000/e1000.c
<#241?email_source=notifications&email_token=AALYOLFVPHCYZEFWER37IWT4TIXEXA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBSHA4TMMJYGM4KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJL3QOJPXEZLWNFSXOX3DNRUWG2Y#discussion_r3008359689>
:
> +
+ /* Number of descriptors that would be required to send this message. */
+ u32 num_desc = CEIL((u32) len, TX_BUF_SIZE);
+
+ u32 head = read_reg(REG_TDH);
+ u32 used = (tx_tail - head + TX_RING_CAP) % TX_RING_CAP;
+ u32 free = TX_RING_CAP - used - 1;
+
+ if (num_desc > free)
+ return -ENOMEM;
+
+ for (u32 i = 0, off = 0; i < num_desc; i++) {
+
+ u32 num = MIN((u32) TX_BUF_SIZE, (u32) len - off);
+
+ __builtin_memcpy(PA_TO_KERNEL_VA(tx_ring[tx_tail].addr), src + off, num);
I think I was having a hard time finding the definition of memcpy
—
Reply to this email directly, view it on GitHub
<#241?email_source=notifications&email_token=AALYOLDD47YGLRJLXILQZW34TIXEXA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTIMBSHA4TMMJYGM4KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJPLQOJPXEZLWNFSXOX3ON52GSZTJMNQXI2LPNZZV6Y3MNFRWW#discussion_r3008359689>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALYOLCPXAOPG3OF657WW7T4TIXEXAVCNFSM6AAAAACXAE5OJ2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHM2DAMRYHE3DCOBTHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Hello @vvaltchev!
This is the e1000 I've been working on. I just wanted to get your first thoughts on the general structure. If everything looks good, I will go through the code again and make sure it follows the contributing guidelines (including squashing the branch and restored and modified files that didn't need to be, such as syscalls.h).