Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
8325105
[gpu] fb
CodeAnarchist Apr 9, 2026
5ce5690
[net] alligment
CodeAnarchist Apr 12, 2026
c416e0c
[net]netpkt across l2-l4
CodeAnarchist Apr 17, 2026
854ad12
[TCP] track passive SYN-ACK and reject orphan accepts
CodeAnarchist Apr 21, 2026
486385d
[tcp] unify rx buffer and fix window managing
CodeAnarchist May 1, 2026
f51e53f
[NET] TCP retransmission, SACK handling, HTTP cont len
CodeAnarchist May 5, 2026
6764f50
[tcp] nagle, minor fixes
CodeAnarchist May 8, 2026
2f9c119
[net] random crash, tx irq-safe
CodeAnarchist May 10, 2026
8be718d
[net/misc] L3/4 cleanup, tcp flow struct split and allocator bug fix
CodeAnarchist May 11, 2026
af9c353
[net] fix virtio init and netpkt lifetime
CodeAnarchist May 12, 2026
0339f24
[net] make packet path full netpkt
CodeAnarchist May 15, 2026
5cde3c5
Merge remote-tracking branch 'upstream/main' into net
CodeAnarchist May 15, 2026
e96c352
Merge remote-tracking branch 'upstream/main' into net
CodeAnarchist May 19, 2026
5e046e9
[tcp] add bounded OOO/SYN/TX limits and seq wrap handling
CodeAnarchist May 21, 2026
f5c8165
Merge branch 'differrari:main' into net
CodeAnarchist May 21, 2026
47638c3
[tcp] move resource accounting into tcp_limits
CodeAnarchist May 22, 2026
0742263
[neigh/virtio] improve tx status and make arp/ndp non blocking
CodeAnarchist May 23, 2026
c30394d
Merge remote-tracking branch 'upstream/main' into net
CodeAnarchist May 23, 2026
ad764db
[dns] add generic dns parser
CodeAnarchist May 25, 2026
1d2b1c1
Merge remote-tracking branch 'upstream/main' into net
CodeAnarchist May 25, 2026
ed4a3b7
[HTTP] HTTP parsing and request limits
CodeAnarchist May 25, 2026
08f7fe7
[http] add chunked HTTP bodies and keep-alive support
CodeAnarchist May 26, 2026
ff52f9e
[http] improve policy and framing
CodeAnarchist May 29, 2026
e3da69e
[network] fix mdns, multicast sockets, http chunked and misc
CodeAnarchist Jun 2, 2026
f7c38f2
[net] refactor socket
CodeAnarchist Jun 4, 2026
2e71ca2
[net] clean up sockets, multicast and tcp lifetime
CodeAnarchist Jun 9, 2026
46f81d4
[http/l3] http policy handling and l3 fragment reassembly
CodeAnarchist Jun 10, 2026
c953e2b
[netpkt] clean up netpkt payload
CodeAnarchist Jun 11, 2026
4291746
Merge remote-tracking branch 'upstream/main' into net
CodeAnarchist Jun 11, 2026
183a7b2
[net] port sockets to c, improve ping and clean up networking
CodeAnarchist Jun 16, 2026
df55303
[net] improve socket options and route epochs
CodeAnarchist Jun 18, 2026
4407dcf
[sock] add special socket base
CodeAnarchist Jun 18, 2026
0aa06e1
[socket] control socket
CodeAnarchist Jun 19, 2026
2141b82
[net]add raw sockets and ipv4 dad
CodeAnarchist Jun 20, 2026
9014a7f
[net ]move ping and traceroute to raw
CodeAnarchist Jun 22, 2026
a413f56
[net] add packet sockets and improve socket options
CodeAnarchist Jun 24, 2026
fcf893c
[sock] add packet/raw filters and special socket flag
CodeAnarchist Jun 24, 2026
5786c14
[net] web routing, reduce network noise, minor fixes
CodeAnarchist Jul 8, 2026
d99dad0
[make/tcp/http] clean builds, flow tracking, range responses
CodeAnarchist Jul 14, 2026
ee05374
[net] batch virtio and improve packet paths
CodeAnarchist Jul 23, 2026
6dbf5e5
[net] add NONBLOCK and DONTROUTE sock options
CodeAnarchist Jul 28, 2026
67685b0
[net] add socket reuse, MAXSEG and linger; known issue with tcp REUS…
CodeAnarchist Jul 31, 2026
4990727
[l4/http] improve tcp, udp and sockets; centralize HTTP helpers
CodeAnarchist Aug 2, 2026
27745f7
[tcp/udp] add sack, dsack and udp sync
CodeAnarchist Aug 6, 2026
17bb12d
[tcp] improve recovery, flow control and conn handling
CodeAnarchist Aug 9, 2026
a6edd20
Merge remote-tracking branch 'upstream/threading' into net
CodeAnarchist Aug 9, 2026
136eee5
[net] add firewall and ip tools, improve socket lifecycle
CodeAnarchist Aug 18, 2026
8b37324
[TERMINAL/TOOLS] clean makes, terminal, unify help
CodeAnarchist Aug 28, 2026
e523eb6
[net] expand l3 if, improve multicast
CodeAnarchist Aug 30, 2026
0b92e72
[net] improve neigh, mtu and pmtu
CodeAnarchist Aug 31, 2026
33f3c3d
[net] imrpove l3 lifecycle and tcp recovery
CodeAnarchist Sep 1, 2026
bdf05e1
[net] make network services demand driven
CodeAnarchist Sep 3, 2026
d7fe21b
[net] improve dhcp/dhcpv6 autoconfig, ipv6 routing
CodeAnarchist Sep 5, 2026
82e0103
[net] bug placeholder gua
CodeAnarchist Sep 5, 2026
7b98a86
[net] route mDNS per L3
CodeAnarchist Sep 6, 2026
03c128f
[net] clean up dns
CodeAnarchist Sep 7, 2026
6eacd75
[net] improve mdns responder
CodeAnarchist Sep 9, 2026
c953a80
[net] improve igmp compatibility
CodeAnarchist Sep 11, 2026
5061fcf
[net] improve ipv6 redirects
CodeAnarchist Sep 13, 2026
f14edbc
[net] fix ipv6 redirect router state
CodeAnarchist Sep 14, 2026
dea1ae2
[net] improve mld v1/v2 compatibility
CodeAnarchist Sep 16, 2026
9f9252a
[net] use ipv6_cpy consistently
CodeAnarchist Sep 16, 2026
2559166
[net] wip improve ntp and timer math
CodeAnarchist Sep 24, 2026
b36eae6
[net] ntp fallback/clock recovery, ep helper
CodeAnarchist Sep 25, 2026
e580a13
[net] move ipv6 on-link routes, improve socket bind
CodeAnarchist Sep 29, 2026
21885cf
[net] add vlan, harden if lifecycle, tcp improvement
CodeAnarchist Oct 9, 2026
9a46577
[net] various optimizations
CodeAnarchist Oct 17, 2026
15b27ba
[net] http parsing, if dns cache, cleanup/optimization
CodeAnarchist Oct 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ else
BOOTFS := /media/bootfs
endif

.PHONY: all shared user kernel clean raspi virt run debug dump prepare-fs help install
.PHONY: all modules kernel shared user tools clean raspi virt run debug dump prepare-fs help install docs

all: kshared modules kernel shared user tools libs docs
@echo "Build complete."
Expand Down Expand Up @@ -51,7 +51,10 @@ clean:
$(MAKE) -C modules $@
$(MAKE) -C libs $@
@echo "removing images"
$(RM) kernel.img kernel.elf dump
$(RM) -f kernel.img kernel.elf disk.img dump trace serial.log gdb_net.log screenlog.0 dump.dtb
$(RM) -f logs/*.log fs/kernel.elf
$(RM) -rf fs/redos/tools fs/redos/system fs/redos/user fs/redos/docs .cache
@find ./user ./tools ./modules ./kernel ./shared ./libs -type f \( -name dump -o -name '*.dump' -o -name '*.trace' -o -name '*.log' -o -name '*.tmp' \) -exec rm -f {} +

raspi:
$(MAKE) LOAD_ADDR=0x80000 XHCI_CTX_SIZE=64 QEMU=true MODE=raspi all
Expand Down
2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COMMON_FLAGS ?= -ffreestanding -nostdlib -fno-exceptions -fno-unwind-tables \
-fno-asynchronous-unwind-tables -g -O0 -Wall -Wextra \
-Wno-unused-parameter -Wno-address-of-packed-member \
-Werror \
-Wno-unused-function
-Wno-unused-function -Wno-missing-field-initializers

ifeq ($(ARCH), aarch64-none-elf-)
COMMON_FLAGS += -mcpu=cortex-a72 -Wno-error=sized-deallocation
Expand Down
10 changes: 10 additions & 0 deletions kernel/exceptions/exception_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
#include "theme/theme.h"
#include "std/string.h"
#include "sysregs.h"
#include "process/syscall.h"

static bool panic_triggered = false;
static bool panic_skip_trace = false;

void set_exception_vectors(){
extern char exception_vectors[];
Expand All @@ -27,7 +29,11 @@ void handle_exception(const char* type, uint64_t info) {
char buf[STRING_MAX_LEN];//no heap to avoid corruption
const char *fmt = "%s \r\nESR_EL1: %llx\r\nELR_EL1: %llx\r\nFAR_EL1: %llx";
string_format_buf(buf, sizeof(buf), fmt,type,esr,elr,far);

bool old_panic_skip_trace = panic_skip_trace;
panic_skip_trace = syscall_depth > 0;
panic(buf, info);
panic_skip_trace = old_panic_skip_trace;
}

void fiq_el1_handler(){ handle_exception("FIQ EXCEPTION\r\n", 0); }
Expand Down Expand Up @@ -61,6 +67,10 @@ void panic(const char* msg, uint64_t info) {
uart_raw_puts("Additional info: ");
uart_puthex(info);
uart_raw_puts("\r\n");
if (!old_panic_triggered && !panic_skip_trace) {
uart_raw_puts("Backtrace:\r\n");
trace();
}
uart_raw_puts("System Halted\r\n");
if (!old_panic_triggered){
char buf[STRING_MAX_LEN];
Expand Down
113 changes: 73 additions & 40 deletions kernel/exceptions/timer.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "timer.h"
#include "irq.h"
#include "math/math.h"

#define TIMER_SLEW_MAX_PPM 500
Expand All @@ -9,7 +10,9 @@ static int g_sync = 0;
static uint64_t g_wall_base_mono_us = 0;
static int64_t g_wall_base_unix_us = 0;
static int32_t g_freq_ppm = 0;
static int64_t g_freq_frac = 0;
static int64_t g_slew_rem_us = 0;
static uint64_t g_slew_frac = 0;

static int32_t g_tz_offset_min = 0;

Expand Down Expand Up @@ -51,7 +54,9 @@ void timer_init(uint64_t msecs) {
g_wall_base_mono_us = timer_now_usec();
g_wall_base_unix_us = 0;
g_freq_ppm = 0;
g_freq_frac = 0;
g_slew_rem_us = 0;
g_slew_frac = 0;
g_sync = 0;
}

Expand Down Expand Up @@ -87,7 +92,9 @@ uint64_t timer_now() {
uint64_t timer_now_msec() {
uint64_t ticks = timer_now();
uint64_t freq = rd_cntfrq_el0();
return (ticks * 1000) / freq;
uint64_t q = ticks / freq;
uint64_t r = ticks % freq;
return q * 1000ULL + (r * 1000ULL) / freq;
}

uint64_t timer_now_usec(void) {
Expand All @@ -110,17 +117,25 @@ static int64_t wall_advance_to(uint64_t mono_now_us) {
int64_t dt = (int64_t)dt_u;

int64_t base = g_wall_base_unix_us;
int64_t adj = dt +(dt * (int64_t)g_freq_ppm)/1000000LL;
base += adj;

int64_t max_slew = (dt * (int64_t)TIMER_SLEW_MAX_PPM) / 1000000LL;
if (max_slew < 1)max_slew = 1;
int64_t dt_sec = dt / 1000000LL;
int64_t dt_rem = dt % 1000000LL;
int64_t freq_num = dt_rem * (int64_t)g_freq_ppm + g_freq_frac;
int64_t freq_adj = dt_sec * (int64_t)g_freq_ppm + freq_num / 1000000LL;
g_freq_frac = freq_num % 1000000LL;
base += dt + freq_adj;

if (g_slew_rem_us) {
int64_t apply = clamp_i64(g_slew_rem_us, -max_slew, max_slew);
g_slew_rem_us -= apply;
base += apply;
}
uint64_t slew_num = (dt_u % 1000000ULL) * (uint64_t)TIMER_SLEW_MAX_PPM + g_slew_frac;
int64_t max_slew = (int64_t)((dt_u / 1000000ULL) * (uint64_t)TIMER_SLEW_MAX_PPM + slew_num / 1000000ULL);
g_slew_frac = slew_num % 1000000ULL;

if (max_slew) {
int64_t apply = clamp_i64(g_slew_rem_us, -max_slew, max_slew);
g_slew_rem_us -= apply;
base += apply;
if (!g_slew_rem_us) g_slew_frac = 0;
}
} else g_slew_frac = 0;

g_wall_base_mono_us = mono_now_us;
g_wall_base_unix_us = base;
Expand All @@ -131,44 +146,65 @@ static int64_t wall_advance_to(uint64_t mono_now_us) {
}

uint64_t timer_wall_time_us(void) {
return (uint64_t)wall_advance_to(timer_now_usec());
irq_flags_t irq = irq_save_disable();
uint64_t us = (uint64_t)wall_advance_to(timer_now_usec());
irq_restore(irq);
return us;
}

uint64_t timer_unix_time_us(void) {
if (!g_sync) return 0;
irq_flags_t irq = irq_save_disable();
if (!g_sync) {
irq_restore(irq);
return 0;
}
int64_t u = wall_advance_to( timer_now_usec());
irq_restore(irq);
if (u < 0) return 0;
return (uint64_t)u;
}

void timer_sync_set_unix_us(uint64_t unix_us) {
irq_flags_t irq = irq_save_disable();
uint64_t now_us = timer_now_usec();
g_wall_base_mono_us = now_us;
g_wall_base_unix_us= (int64_t)unix_us;
g_freq_frac = 0;
g_slew_rem_us = 0;
g_slew_frac = 0;
g_sync = 1;
irq_restore(irq);
}

void timer_sync_slew_us(int64_t delta_us){
irq_flags_t irq = irq_save_disable();
wall_advance_to(timer_now_usec());
const int64_t cap = 60LL * 1000000LL;
int64_t v = g_slew_rem_us + delta_us;
g_slew_rem_us = clamp_i64(v, -cap, cap);
g_slew_rem_us = clamp_i64(delta_us, -cap, cap);
g_slew_frac = 0;
irq_restore(irq);
}

void timer_sync_set_freq_ppm(int32_t ppm) {
irq_flags_t irq = irq_save_disable();
wall_advance_to(timer_now_usec());
g_freq_ppm = clamp_i64((int32_t)ppm, -TIMER_FREQ_MAX_PPM, TIMER_FREQ_MAX_PPM);
g_freq_frac = 0;
irq_restore(irq);
}

int32_t timer_sync_get_freq_ppm(void) {
return g_freq_ppm;
}

void timer_apply_sntp_sample_us(uint64_t server_unix_us) {
timer_sync_set_unix_us(server_unix_us);
irq_flags_t irq = irq_save_disable();
int32_t ppm = g_freq_ppm;
irq_restore(irq);
return ppm;
}

int timer_is_synchronised(void) {
return g_sync;
irq_flags_t irq = irq_save_disable();
int sync = g_sync;
irq_restore(irq);
return sync;
}

uint64_t timer_unix_time_ms(void) {
Expand All @@ -194,10 +230,18 @@ uint64_t timer_local_time_ms(void){
}

int timer_set_manual_unix_time_ms(uint64_t unix_ms){
if (g_sync) return -1;
irq_flags_t irq = irq_save_disable();
if (g_sync) {
irq_restore(irq);
return -1;
}
uint64_t now_us = timer_now_usec();
g_wall_base_mono_us = now_us;
g_wall_base_unix_us = (int64_t)(unix_ms * 1000ULL);
g_freq_frac = 0;
g_slew_rem_us = 0;
g_slew_frac = 0;
irq_restore(irq);
return 0;
}

Expand All @@ -224,10 +268,9 @@ static void civil_from_days(int64_t z, int64_t* y, unsigned* m, unsigned* d){
*y = y_full; *m = mm; *d = dd;
}

static void fmt2u(uint64_t v, char out[3]){ //maybe move this in a helper file
static inline void fmt2u(uint32_t v, char out[2]){ //maybe move this in a helper file
out[0] = (char)('0' + (v/10u)%10u);
out[1] = (char)('0' + (v%10u));
out[2] = '\0';
}

void timer_unix_ms_to_datetime(uint64_t unix_ms, int use_local, DateTime* out){
Expand Down Expand Up @@ -281,28 +324,18 @@ int timer_now_datetime(DateTime* out, int use_local){

void timer_datetime_to_string(const DateTime* dt, char* buf, uint32_t buflen){
if (!dt || !buf || buflen < 20) return;
uint16_t Y = dt->year;
buf[0] = (char)('0' + (Y/1000)%10);
buf[1] = (char)('0' + (Y/100)%10);
buf[2] = (char)('0' + (Y/10)%10);
buf[3] = (char)('0' + (Y%10));
fmt2u(dt->year/100, buf);
fmt2u(dt->year, buf + 2);
buf[4] = '-';

char mm[3], dd[3], HH[3], MM[3], SS[3];
fmt2u(dt->month, mm);
fmt2u(dt->day, dd);
fmt2u(dt->hour, HH);
fmt2u(dt->minute, MM);
fmt2u(dt->second, SS);

buf[5] = mm[0]; buf[6] = mm[1];
fmt2u(dt->month, buf + 5);
buf[7] = '-';
buf[8] = dd[0]; buf[9] = dd[1];
fmt2u(dt->day, buf + 8);
buf[10] = ' ';
buf[11] = HH[0]; buf[12] = HH[1];
fmt2u(dt->hour, buf + 11);
buf[13] = ':';
buf[14] = MM[0]; buf[15] = MM[1];
fmt2u(dt->minute, buf + 14);
buf[16] = ':';
buf[17] = SS[0]; buf[18] = SS[1];
fmt2u(dt->second, buf + 17);
buf[19] = '\0';
}
2 changes: 0 additions & 2 deletions kernel/exceptions/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ uint64_t timer_now_usec(void);
uint64_t timer_wall_time_us(void);
uint64_t timer_unix_time_us(void);

void timer_apply_sntp_sample_us(uint64_t server_unix_us);

void timer_sync_set_unix_us(uint64_t unix_us);
void timer_sync_slew_us(int64_t delta_us);
void timer_sync_set_freq_ppm(int32_t ppm);
Expand Down
4 changes: 2 additions & 2 deletions kernel/fw/fw_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "console/kio.h"
#include "std/memory_access.h"
#include "memory/mmu.h"
#include "memory/addr.h"
#include "async.h"
#include "sysregs.h"
#include "std/string.h"
Expand Down Expand Up @@ -44,7 +45,6 @@ void fw_cfg_dma_operation(void* dest, uint32_t size, uint32_t ctrl) {
};

write64(PHYS_TO_VIRT(FW_CFG_DMA), __builtin_bswap64(pt_va_to_pa(&access)));

__asm__("isb");

if (!wait(&access.control, __builtin_bswap32(~0x1), false, 2000)){
Expand All @@ -71,7 +71,7 @@ bool fw_find_file(const char* search, struct fw_cfg_file *file) {

if (!fw_cfg_check())
return false;

u32 count = 0;
fw_cfg_dma_read(&count, sizeof(count), FW_LIST_DIRECTORY);

Expand Down
1 change: 1 addition & 0 deletions kernel/memory/addr.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "addr.h"
#include "va_layout.h"

#include "va_layout.h"

Expand Down
11 changes: 6 additions & 5 deletions kernel/memory/page_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ void setup_page(uintptr_t address, uint8_t attributes){
}

paddr_t palloc_inner(uint64_t size, uint8_t level, uint8_t attributes, bool full, bool map) {
if (!size) return 0;
if (!alloc_max_page) page_alloc_init();
if (!page_alloc_high_va) page_alloc_enable_high_va();
uint64_t page_count = count_pages(size,PAGE_SIZE);
Expand Down Expand Up @@ -263,10 +264,10 @@ paddr_t palloc_inner(uint64_t size, uint8_t level, uint8_t attributes, bool full

uint64_t inv = ~mem_bitmap[i];
uint64_t bit = __builtin_ctzll(inv);
if (bit > (64 - page_count)){
continue;
}
while (bit < 64) {
uint64_t max_bit = 64 - page_count;
if (bit > max_bit) continue;

while (bit <= max_bit) {
bool found = true;
for (uint64_t b = bit; b < bit + page_count; b++){
if ((mem_bitmap[i] >> b) & 1ull){
Expand All @@ -277,7 +278,7 @@ paddr_t palloc_inner(uint64_t size, uint8_t level, uint8_t attributes, bool full
}
if (found) break;
}
if (bit >= 64) continue;
if (bit > max_bit) continue;
uintptr_t first_address = 0;
mem_page* prev_page = 0;

Expand Down
Loading
Loading