SayoriOS 0.3.3

stack.c
1 //
2 // Created by maractus on 04.01.24.
3 //
4
5 #include "net/cards.h"
6 #include "net/stack.h"
7 #include "../lib/libvector/include/vector.h"
8 #include "mem/vmm.h"
9 #include "io/ports.h"
10 #include "sys/scheduler.h"
11 #include "net/ethernet.h"
12
13 volatile vector_t* system_network_incoming_queue = 0;
14
15 void netstack_processor();
16
17 void netstack_init() {
18 system_network_incoming_queue = vector_new();
19
20 thread_create(get_current_proc(), netstack_processor, 0x10000, true, false);
21 }
22
23 void netstack_push(netcard_entry_t* card, void* packet_data, size_t length) {
24 netqueue_item_t* item = kcalloc(sizeof(netqueue_item_t), 1);
25 void* data = kcalloc(1, length);
26
27 memcpy(data, packet_data, length);
28
29 item->data = data;
30 item->card = card;
31 item->length = length;
32
33 vector_push_back(system_network_incoming_queue, (size_t) item);
34 }
35
36 netqueue_item_t* netstack_pop() {
37 netqueue_item_t* data = (void *) vector_pop_back(system_network_incoming_queue).element;
38
39 return data;
40 }
41
42 netqueue_item_t* netstack_poll() {
43 while(system_network_incoming_queue->size == 0);
44
45 return netstack_pop();
46 }
47
48
49 void netstack_processor() {
50 qemu_note("NETWORK QUEUE IS WORKING NOW!");
51
52 while(1) {
53 qemu_note("WAITING FOR PACKET");
54 netqueue_item_t* item = netstack_poll();
55
56 qemu_note("SENDING PACKET");
57 item->card->send_packet(item->data, item->length);
58 //ethernet_handle_packet(item->card, item->data, item->length);
59
60 qemu_ok("PACKET SENT!");
61 }
62 }
memcpy
void * memcpy(void *restrict destination, const void *restrict source, size_t n)
Копирование непересекающихся массивов используя SSE.
Definition: string.c:173
get_current_proc
volatile process_t * get_current_proc(void)
Получить текущий обработчик процесса
Definition: scheduler.c:125
netcard_entry_t
Definition: cards.h:5
netqueue_item_t
Definition: stack.h:10
vector
Definition: vector.h:7