Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
df0209a
Initializing mulitple virtqueues for multiple devices
Jun 14, 2025
5ccce8c
virtqueue proper size
Jun 15, 2025
e44305b
Printing mac address
Jun 16, 2025
a7509ec
Moved XHCI init to ensure it happens right before MMU enable
Jun 16, 2025
61e177f
Added feature mask and correct notif for each queue
Jun 17, 2025
4ad0cb8
Sending a test udp packet broadcast on local network
Jun 17, 2025
3f7bf4a
Send3 -> send1d
Jun 17, 2025
9d46347
Setup buffers for receiving
Jun 17, 2025
b97fa79
Fixed checksums
Jun 17, 2025
bc2c6ce
Moved MAC/IP constants to own gitignored file
Jun 18, 2025
19e9460
Enabling interrupts for network
Jun 18, 2025
70b4afb
network verbosity
Jun 18, 2025
7a5dae1
Receive and parse UDP packets
Jun 18, 2025
4ca8095
Created (currently unused) network dispatch
Jun 18, 2025
764cf6e
Rewrite net driver in C++
Jun 18, 2025
d60056f
Send packets through cpp driver, receiving works but not from test se…
Jun 18, 2025
c685664
Network process for testing (and probably config/monitoring)
Jun 18, 2025
d118a7b
Restored UDP packet parsing
Jun 19, 2025
69599b3
Moved to network_types.h name, process port binding
Jun 19, 2025
a6517cd
Receiver fix and network types to shared
Jun 19, 2025
4409964
Send data to process
Jun 19, 2025
a9941c6
Payload reading in process
Jun 19, 2025
eedee5e
Renamed ReceivedPacket to sizedptr
Jun 19, 2025
6c4cd0c
syscalls for network
Jun 19, 2025
f11a1f6
Moved UDP parser to shared
Jun 19, 2025
9eca4e1
Payload print and copy fixes
Jun 19, 2025
2c612e8
Moved network types to net folder
Jun 19, 2025
1397071
DHCP negotiation to receive an IP from router
Jun 20, 2025
a2045d0
Rearranged networking files
Jun 20, 2025
82dd703
Started to implement ARP
Jun 20, 2025
b1887da
Finished DHCP and continuing ARP
Jun 20, 2025
b5b1e4d
Untested, possibly broken ARP responses
Jun 20, 2025
f09614c
IPV4 into own files, starting to implement ICMP
Jun 20, 2025
10212fa
ARP fixes
Jun 20, 2025
ed18219
Half functioning ping response
Jun 20, 2025
0d57c03
Fixed checksum for ipv4 and icmp
Jun 20, 2025
fc4d7b3
Cleaned up the DHCP negotiation code with 5 retries (no timeout)
Jun 20, 2025
78f593d
Lease renegotiation
Jun 20, 2025
5a5c8d3
Sending one TCP packet
Jun 20, 2025
4890064
Moved checksums
Jun 20, 2025
1fac1e0
Messy but tcp 3w handshake
Jun 21, 2025
9a7af29
Connection reset, reusable TCP functions
Jun 21, 2025
80b059b
Moving tcp code to tcp library
Jun 21, 2025
c930b9d
printf and out response payload
Jun 21, 2025
27e05b8
Temporarily moved all TCP/HTTP code back to kernel cause I'm too lazy…
Jun 21, 2025
94ddbab
Moved all packets to shared lib
Jun 22, 2025
35bae50
Fixed printf and empty http responses
Jun 22, 2025
da3e4b3
Restored http and tcp to their library
Jun 22, 2025
5c14db4
Full HTTP payload parsing
Jun 22, 2025
b49fe13
Interrupts for upload, freeing memory
Jun 22, 2025
64caf77
Free received packets
Jun 22, 2025
a872c8f
Moving packet creation to dispatch
Jun 23, 2025
7506dc4
Moved context out of driver
Jun 23, 2025
c39ee20
Use UDP for server discovery
Jun 24, 2025
78eb6c2
Fixed port
Jun 24, 2025
4bce572
Expecting 'world' from server
Jun 24, 2025
7e3aef7
Updated README
Jun 24, 2025
d63d031
removed gitignored file
Jun 24, 2025
4c14a0b
Restored max_packet_size
Jun 24, 2025
9a7c453
UDP uses sizedptr
Jun 24, 2025
8f02812
Format, comment, print and header location fixes
Jun 24, 2025
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
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Once the system is initialized, most of the system's functionality is provided b
Certain parts of the system initialization, such as GPU initialization and XHCI input code initialization rely on some syscalls that expect a process to be running, so an initial kernel.c process is created to hold their data. In the future they'll each have their own process.
Everything about kernel processes and the pseudo-processes mentioned for GPU/XHCI will most likley be improved in the future, to make the system more modular, and kernel processes might get loaded from filesystem, in a similar way to how user processes are loaded. In order to do this, they either need to not rely on any kernel-only code (as several of them currently do) and rely on syscalls entirely, or (less ideal) dynamically link to the kernel. Doing this will increase the kernel's modularity.

The system currently heavily relies on symbols defined in the linker to run, and these symbols are not available in the stripped binary version of the kernel, so REDACTED OS must be run through the kernel.elf file rather than the kernel.bin file.
This limitation will be lifted in the future, removing reliance on these symbols altogether when possible, and creating alternatives for them when they're needed.
The system must be run through the .elf file, since the .img file overwrites the device's DTB, making it impossible to detect certain features of the system.
This limitation will be lifted in the future.

### Shared

Expand Down Expand Up @@ -64,3 +64,8 @@ In order to run the OS, you'll need to create a folder called fs inside the proj

Github Actions should automatically compile changes made to the `main` branch using Mac, so a compiled version of the system with all the files needed to run it should be found there. This includes the fs folder, containing the filesystem, but you'll need to recompile the `disk.img` filesystem with `createfs` for any changes made to this folder to be reflected.

## Networking

The system has basic networking support. Currently, it performs DHCP a discovery and request to receive an IP address on the local network, is capable of responding to Ping and ARP, and can connect to a server running on ports 8080 and 80, though it currently does nothing noteworthy.
An implementation of the server can be found at the [RedactedOS Firmware Server Repository](https://github.com/differrari/RedactedOS_firmware_server/tree/main)

4 changes: 2 additions & 2 deletions kernel/exceptions/exception_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void panic(const char* panic_msg) {
kstring s = kstring_format("%s\n%s\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)panic_msg);
draw_panic_screen(s);
}
while (1);
while (1);//TODO: OPT
}

void panic_with_info(const char* msg, uint64_t info) {
Expand All @@ -92,5 +92,5 @@ void panic_with_info(const char* msg, uint64_t info) {
kstring s = kstring_format("%s\n%s\nError code: %x\nSystem Halted",(uint64_t)PANIC_TEXT,(uint64_t)msg,info);
draw_panic_screen(s);
}
while (1);
while (1);//TODO: OPT
}
11 changes: 11 additions & 0 deletions kernel/exceptions/irq.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "pci.h"
#include "input/xhci.h"
#include "console/serial/uart.h"
#include "networking/network.h"

#define IRQ_TIMER 30
#define SLEEP_TIMER 27
Expand Down Expand Up @@ -36,6 +37,8 @@ void irq_init() {

gic_enable_irq(IRQ_TIMER, 0x80, 0);
gic_enable_irq(MSI_OFFSET + XHCI_IRQ, 0x80, 0);
gic_enable_irq(MSI_OFFSET + NET_IRQ, 0x80, 0);
gic_enable_irq(MSI_OFFSET + NET_IRQ + 1, 0x80, 0);
gic_enable_irq(SLEEP_TIMER, 0x80, 0);

write32(GICC_BASE + 0x004, 0xF0); //Priority
Expand Down Expand Up @@ -75,6 +78,14 @@ void irq_el1_handler() {
wake_processes();
write32(GICC_BASE + 0x10, irq);
process_restore();
} else if (irq == MSI_OFFSET + NET_IRQ){
network_handle_download_interrupt();
write32(GICC_BASE + 0x10, irq);
process_restore();
} else if (irq == MSI_OFFSET + NET_IRQ + 1){
network_handle_upload_interrupt();
write32(GICC_BASE + 0x10, irq);
process_restore();
} else {
kprintf_raw("[GIC error] Received unknown interrupt");
write32(GICC_BASE + 0x10, irq);
Expand Down
30 changes: 6 additions & 24 deletions kernel/input/xhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,53 +93,35 @@ void make_ring_link(trb* ring, bool cycle){
make_ring_link_control(ring, cycle);
}


uint8_t xhci_init_interrupts(uint64_t pci_addr){
#define MSIX_IRQ_LENGTH 1
msix_irq_line irq_lines[MSIX_IRQ_LENGTH] = {(msix_irq_line){.addr_offset=0,.irq_num=XHCI_IRQ}};
bool msix_ok = pci_setup_msix(pci_addr, irq_lines, MSIX_IRQ_LENGTH);

if(msix_ok){
return 1;
}

bool msi_ok = pci_setup_msi(pci_addr, XHCI_IRQ);
if(msi_ok){
return 2;
}

return 0;
}

bool xhci_init(xhci_device *xhci, uint64_t pci_addr) {
kprintfv("[xHCI] init");
if (!(read16(pci_addr + 0x06) & (1 << 4))){
kprintfv("[xHCI] Wrong capabilities list");
return false;
}

pci_enable_device(pci_addr);

if (!pci_setup_bar(pci_addr, 0, &xhci->mmio, &xhci->mmio_size)){
kprintfv("[xHCI] BARs not set up");
return false;
}

pci_register(xhci->mmio, xhci->mmio_size);

uint8_t interrupts_ok = xhci_init_interrupts(pci_addr);
uint8_t interrupts_ok = pci_setup_interrupts(pci_addr, XHCI_IRQ, 1);
switch(interrupts_ok){
case 0:
kprintf_raw("[xHCI] Failed to setup interrupts\n");
kprintf_raw("[xHCI] Failed to setup interrupts");
return false;
case 1:
kprintf_raw("[xHCI] Interrupts setup with MSI-X");
kprintf_raw("[xHCI] Interrupts setup with MSI-X %i",XHCI_IRQ);
break;
default:
kprintf_raw("[xHCI] Interrupts setup with MSI");
kprintf_raw("[xHCI] Interrupts setup with MSI %i",XHCI_IRQ);
break;
}

pci_enable_device(pci_addr);

kprintfv("[xHCI] BARs set up @ %x (%x)",xhci->mmio,xhci->mmio_size);

xhci->cap = (xhci_cap_regs*)(uintptr_t)xhci->mmio;
Expand Down
18 changes: 10 additions & 8 deletions kernel/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include "input/xhci_bridge.h"
#include "input/xhci.h"
#include "kernel_processes/monitor/monitor_processes.h"
#include "networking/processes/net_proc.h"
#include "memory/page_allocator.h"

#include "networking/virtio_net_pci.h"
#include "networking/network.h"

void kernel_main() {

Expand Down Expand Up @@ -46,18 +46,18 @@ void kernel_main() {

kprintf("GPU initialized");

// xhci_enable_verbose();
if (!xhci_input_init()){
panic("Input initialization failure");
}

kprintf("Initializing disk...");

// disk_verbose();
if (!find_disk())
panic("Disk initialization failure");

if (!vnp_find_network())
// xhci_enable_verbose();
if (!xhci_input_init()){
panic("Input initialization failure");
}

if (!network_init())
panic("Network initialization failure");

mmu_init();
Expand All @@ -72,6 +72,8 @@ void kernel_main() {

// translate_enable_verbose();

launch_net_process();

init_bootprocess();

kprintf("Starting scheduler");
Expand Down
2 changes: 1 addition & 1 deletion kernel/kernel_processes/monitor/monitor_processes.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void print_process_info(){
for (int i = 0; i < MAX_PROCS; i++){
process_t *proc = &processes[i];
if (proc->id != 0 && proc->state != STOPPED){
printf("Process [%i]: %s [pid = %i | status = %s]",i,(uintptr_t)proc->name,proc->id,(uint64_t)parse_proc_state(proc->state));
printf("Process [%i]: %s [pid = %i | status = %s]",i,(uintptr_t)proc->name,proc->id,(uintptr_t)parse_proc_state(proc->state));
printf("Stack: %x (%x). SP: %x",proc->stack, proc->stack_size, proc->sp);
printf("Heap: %x (%x)",proc->heap, calc_heap(proc->heap));
printf("Flags: %x", proc->spsr);
Expand Down
3 changes: 3 additions & 0 deletions kernel/memory/kalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ uint64_t alloc_mmio_region(uint64_t size) {
return addr;
}

bool is_mmio_allocated(uint64_t addr){
return addr > PCI_MMIO_BASE && addr < next_mmio_base;
}

extern uint64_t kernel_start;
extern uint64_t heap_bottom;
Expand Down
4 changes: 3 additions & 1 deletion kernel/memory/kalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ uint64_t get_user_ram_end();
uint64_t get_shared_start();
uint64_t get_shared_end();

uint64_t alloc_mmio_region(uint64_t size);
uint64_t alloc_mmio_region(uint64_t size);

bool is_mmio_allocated(uint64_t addr);
4 changes: 4 additions & 0 deletions kernel/memory/page_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,8 @@ void free_from_page(void* ptr, uint64_t size) {
block->next = page->free_list;
page->free_list = block;
page->size -= size;
}

void free_sized(sizedptr ptr){
free_from_page((void*)ptr.ptr, ptr.size);
}
2 changes: 2 additions & 0 deletions kernel/memory/page_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void free_page(void* ptr, uint64_t size);
void* allocate_in_page(void *page, uint64_t size, uint16_t alignment, bool kernel, bool device);
void free_from_page(void* ptr, uint64_t size);

void free_sized(sizedptr ptr);

#ifdef __cplusplus
}
#endif
28 changes: 28 additions & 0 deletions kernel/networking/drivers/net_driver.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "types.h"
#include "std/string.h"
#include "ui/graphic_types.h"
#include "net/network_types.h"

class NetDriver {
public:
NetDriver(){}
virtual bool init() = 0;

virtual sizedptr allocate_packet(size_t size) = 0;

virtual sizedptr handle_receive_packet() = 0;

virtual void handle_sent_packet() = 0;

virtual void enable_verbose() = 0;

virtual void send_packet(sizedptr packet) = 0;

virtual void get_mac(network_connection_ctx *context) = 0;

virtual ~NetDriver() = default;

uint16_t header_size;
};
Loading