aboutsummaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
authorMarvin Borner2020-11-20 19:15:21 +0100
committerMarvin Borner2020-11-20 19:15:21 +0100
commit38e0d413e38838979978d6ff3fdbaf577a916fd0 (patch)
treeee2536759f602fa502bbc038ae3a8464656fffdc /kernel
parent5708ab26c0de8fc1be3e96a0f3f092da0938169e (diff)
Some fixes here and there
Ya, professional commit messages as always
Diffstat (limited to 'kernel')
-rw-r--r--kernel/features/fs.c30
-rw-r--r--kernel/features/net.c21
-rw-r--r--kernel/features/syscall.c2
-rw-r--r--kernel/inc/fs.h1
-rw-r--r--kernel/main.c2
5 files changed, 14 insertions, 42 deletions
diff --git a/kernel/features/fs.c b/kernel/features/fs.c
index 941ba76..41aca78 100644
--- a/kernel/features/fs.c
+++ b/kernel/features/fs.c
@@ -161,33 +161,3 @@ u32 find_inode(const char *name, u32 dir_inode)
free(buf);
return (unsigned)-1;
}
-
-void ls_root(void)
-{
- struct inode *i = get_inode(2);
-
- char *buf = malloc(BLOCK_SIZE * i->blocks / 2);
-
- for (u32 q = 0; q < i->blocks / 2; q++) {
- char *data = buffer_read(i->block[q]);
- memcpy((u32 *)((u32)buf + q * BLOCK_SIZE), data, BLOCK_SIZE);
- }
-
- struct dirent *d = (struct dirent *)buf;
-
- u16 calc = 0;
- int sum = 0;
- printf("\nRoot directory:\n");
- do {
- calc = (sizeof(struct dirent) + d->name_len + 4) & (u32)~0x3;
- sum += d->total_len;
- d->name[d->name_len] = '\0';
- printf("/%s\n", d->name);
- if (d->total_len != calc && sum == 1024)
- d->total_len = calc;
-
- d = (struct dirent *)((u32)d + d->total_len);
-
- } while (sum < 1024);
- printf("\n");
-}
diff --git a/kernel/features/net.c b/kernel/features/net.c
index 436ad88..2e4f6cf 100644
--- a/kernel/features/net.c
+++ b/kernel/features/net.c
@@ -323,7 +323,7 @@ static void tcp_send_packet(struct socket *socket, u16 flags, void *data, int le
packet->seq_number = htonl(socket->prot.tcp.seq_no);
packet->ack_number = flags & TCP_FLAG_ACK ? htonl(socket->prot.tcp.ack_no) : 0;
packet->flags = (u16)htons(0x5000 ^ (flags & 0xff));
- packet->window_size = htons((2 << 15) - 1); // TODO: Support TCP windows
+ packet->window_size = htons(U16_MAX); // TODO: Support TCP windows
packet->urgent = 0;
packet->checksum = 0; // Later
@@ -494,7 +494,7 @@ static void tcp_handle_packet(struct tcp_packet *packet, u32 dst, int len)
socket->state = S_CONNECTED;
tcp->state++;
return;
- } else if (tcp->state == 6 && (flags & 0xff) == (TCP_FLAG_ACK | TCP_FLAG_PSH)) {
+ } else if (tcp->state == 6 && flags & TCP_FLAG_ACK) {
struct socket_data *sdata = malloc(sizeof(*sdata));
sdata->length = data_length;
if (sdata->length) {
@@ -504,16 +504,19 @@ static void tcp_handle_packet(struct tcp_packet *packet, u32 dst, int len)
sdata->data = NULL;
}
list_add(socket->packets, sdata);
- proc_from_pid(socket->pid)->state = PROC_RUNNING;
tcp->ack_no += data_length;
tcp->seq_no = recv_ack;
- tcp_send_packet(socket, TCP_FLAG_ACK, NULL, 0);
- tcp_send_packet(socket, TCP_FLAG_FIN | TCP_FLAG_ACK, NULL, 0);
+ // TODO: How many segments are going to be sent?!
+ if ((flags & 0xff) == (TCP_FLAG_ACK | TCP_FLAG_PSH)) {
+ proc_from_pid(socket->pid)->state = PROC_RUNNING;
+ tcp_send_packet(socket, TCP_FLAG_ACK, NULL, 0);
+ tcp_send_packet(socket, TCP_FLAG_FIN | TCP_FLAG_ACK, NULL, 0);
+ tcp->state++;
+ }
socket->state = S_CONNECTED;
- tcp->state++;
return;
} else if (tcp->state == 7 && (flags & 0xff) == (TCP_FLAG_ACK | TCP_FLAG_FIN)) {
tcp->ack_no = recv_seq + 1;
@@ -834,9 +837,10 @@ void net_install(void)
}
// DHCP timeout (no gateway address)
+ sti();
u32 time = timer_get();
while (!gateway_addr && timer_get() - time < 1000)
- timer_wait(10);
+ ;
if (timer_get() - time >= 1000) {
print("DHCP timeout\n");
@@ -845,9 +849,10 @@ void net_install(void)
}
// ARP lookup timeout
+ sti();
time = timer_get();
while (!arp_lookup(gateway_mac, gateway_addr) && timer_get() - time < 1000)
- timer_wait(10);
+ ;
if (timer_get() - time >= 1000) {
printf("Gateway ARP timeout at address %x\n", gateway_addr);
diff --git a/kernel/features/syscall.c b/kernel/features/syscall.c
index 0328f47..ac89d04 100644
--- a/kernel/features/syscall.c
+++ b/kernel/features/syscall.c
@@ -98,7 +98,7 @@ void syscall_handler(struct regs *r)
}
case SYS_NET_CLOSE: {
struct socket *s = (void *)r->ebx;
- if (s->type == S_TCP && s->state != S_CLOSED) {
+ if (s->type == S_TCP && s->state == S_CONNECTED) {
proc_current()->state = PROC_SLEEPING;
proc_yield(r);
return;
diff --git a/kernel/inc/fs.h b/kernel/inc/fs.h
index d7e3544..93d2013 100644
--- a/kernel/inc/fs.h
+++ b/kernel/inc/fs.h
@@ -97,6 +97,5 @@ u32 find_inode(const char *name, u32 dir_inode);
struct inode *get_inode(u32 i);
void *read_inode(struct inode *in);
void *read_file(char *path);
-void ls_root(void); // DEMO ;)
#endif
diff --git a/kernel/main.c b/kernel/main.c
index d567963..5e071a9 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -37,8 +37,6 @@ void kernel_main(struct vid_info *vid_info)
// Enable drivers
sti();
- ls_root();
-
syscall_init();
proc_init();