mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
UDP Msg receive update
This commit is contained in:
parent
0c44c3b660
commit
931f235372
18 changed files with 143 additions and 15 deletions
7
Makefile
7
Makefile
|
|
@ -2,22 +2,18 @@
|
||||||
# Target Architecture: x86_64
|
# Target Architecture: x86_64
|
||||||
# Host: macOS
|
# Host: macOS
|
||||||
|
|
||||||
# Toolchain Definitions
|
|
||||||
CC = x86_64-elf-gcc
|
CC = x86_64-elf-gcc
|
||||||
LD = x86_64-elf-ld
|
LD = x86_64-elf-ld
|
||||||
NASM = nasm
|
NASM = nasm
|
||||||
XORRISO = xorriso
|
XORRISO = xorriso
|
||||||
|
|
||||||
# Directories
|
|
||||||
SRC_DIR = src/kernel
|
SRC_DIR = src/kernel
|
||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
ISO_DIR = iso_root
|
ISO_DIR = iso_root
|
||||||
|
|
||||||
# Output
|
|
||||||
KERNEL_ELF = $(BUILD_DIR)/brewos.elf
|
KERNEL_ELF = $(BUILD_DIR)/brewos.elf
|
||||||
ISO_IMAGE = brewos.iso
|
ISO_IMAGE = brewos.iso
|
||||||
|
|
||||||
# Source Files
|
|
||||||
C_SOURCES = $(wildcard $(SRC_DIR)/*.c)
|
C_SOURCES = $(wildcard $(SRC_DIR)/*.c)
|
||||||
CLI_APP_SOURCES = $(wildcard $(SRC_DIR)/cli_apps/*.c)
|
CLI_APP_SOURCES = $(wildcard $(SRC_DIR)/cli_apps/*.c)
|
||||||
ASM_SOURCES = $(wildcard $(SRC_DIR)/*.asm)
|
ASM_SOURCES = $(wildcard $(SRC_DIR)/*.asm)
|
||||||
|
|
@ -25,7 +21,6 @@ OBJ_FILES = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES)) \
|
||||||
$(patsubst $(SRC_DIR)/cli_apps/%.c, $(BUILD_DIR)/cli_apps/%.o, $(CLI_APP_SOURCES)) \
|
$(patsubst $(SRC_DIR)/cli_apps/%.c, $(BUILD_DIR)/cli_apps/%.o, $(CLI_APP_SOURCES)) \
|
||||||
$(patsubst $(SRC_DIR)/%.asm, $(BUILD_DIR)/%.o, $(ASM_SOURCES))
|
$(patsubst $(SRC_DIR)/%.asm, $(BUILD_DIR)/%.o, $(ASM_SOURCES))
|
||||||
|
|
||||||
# Flags
|
|
||||||
CFLAGS = -g -O2 -pipe -Wall -Wextra -std=gnu11 -ffreestanding \
|
CFLAGS = -g -O2 -pipe -Wall -Wextra -std=gnu11 -ffreestanding \
|
||||||
-fno-stack-protector -fno-stack-check -fno-lto -fPIE \
|
-fno-stack-protector -fno-stack-check -fno-lto -fPIE \
|
||||||
-m64 -march=x86-64 -mno-80387 -mno-mmx -mno-sse -mno-sse2 -mno-red-zone \
|
-m64 -march=x86-64 -mno-80387 -mno-mmx -mno-sse -mno-sse2 -mno-red-zone \
|
||||||
|
|
@ -123,4 +118,4 @@ clean:
|
||||||
run: $(ISO_IMAGE)
|
run: $(ISO_IMAGE)
|
||||||
qemu-system-x86_64 -m 2G -serial stdio -cdrom $(ISO_IMAGE) -boot d \
|
qemu-system-x86_64 -m 2G -serial stdio -cdrom $(ISO_IMAGE) -boot d \
|
||||||
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0 \
|
-audiodev coreaudio,id=audio0 -machine pcspk-audiodev=audio0 \
|
||||||
-netdev user,id=net0 -device e1000,netdev=net0
|
-netdev user,id=net0,hostfwd=udp::12345-:12345 -device e1000,netdev=net0
|
||||||
|
|
|
||||||
BIN
brewos.iso
BIN
brewos.iso
Binary file not shown.
BIN
build/brewos.elf
BIN
build/brewos.elf
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
build/cmd.o
BIN
build/cmd.o
Binary file not shown.
BIN
build/editor.o
BIN
build/editor.o
Binary file not shown.
BIN
build/network.o
BIN
build/network.o
Binary file not shown.
BIN
build/wm.o
BIN
build/wm.o
Binary file not shown.
Binary file not shown.
|
|
@ -45,6 +45,7 @@ void cli_cmd_netinfo(char *args);
|
||||||
void cli_cmd_ipset(char *args);
|
void cli_cmd_ipset(char *args);
|
||||||
void cli_cmd_udpsend(char *args);
|
void cli_cmd_udpsend(char *args);
|
||||||
void cli_cmd_udptest(char *args);
|
void cli_cmd_udptest(char *args);
|
||||||
|
void cli_cmd_msgrc(char *args);
|
||||||
|
|
||||||
// PCI commands
|
// PCI commands
|
||||||
void cli_cmd_pcilist(char *args);
|
void cli_cmd_pcilist(char *args);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "cli_utils.h"
|
#include "cli_utils.h"
|
||||||
#include "fat32.h"
|
#include "fat32.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
|
||||||
void cli_cmd_cd(char *args) {
|
void cli_cmd_cd(char *args) {
|
||||||
if (!args || args[0] == 0) {
|
if (!args || args[0] == 0) {
|
||||||
|
|
@ -221,6 +222,10 @@ void cli_cmd_cat(char *args) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
filename[i] = 0;
|
filename[i] = 0;
|
||||||
|
|
||||||
|
if (cli_strcmp(filename, "messages") == 0) {
|
||||||
|
cmd_reset_msg_count();
|
||||||
|
}
|
||||||
|
|
||||||
FAT32_FileHandle *fh = fat32_open(filename, "r");
|
FAT32_FileHandle *fh = fat32_open(filename, "r");
|
||||||
if (!fh) {
|
if (!fh) {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,8 @@
|
||||||
#include "cli_utils.h"
|
#include "cli_utils.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
#include "fat32.h"
|
||||||
|
#include "cmd.h"
|
||||||
|
#include "memory_manager.h"
|
||||||
|
|
||||||
static void print_mac(const mac_address_t* mac){
|
static void print_mac(const mac_address_t* mac){
|
||||||
char buf[64];
|
char buf[64];
|
||||||
|
|
@ -97,11 +100,35 @@ void cli_cmd_udpsend(char *args){
|
||||||
|
|
||||||
static void udp_print_callback(const ipv4_address_t* src_ip,uint16_t src_port,const mac_address_t* src_mac,const void* data,size_t length){
|
static void udp_print_callback(const ipv4_address_t* src_ip,uint16_t src_port,const mac_address_t* src_mac,const void* data,size_t length){
|
||||||
(void)src_mac;
|
(void)src_mac;
|
||||||
cli_write("UDP from ");
|
|
||||||
for(int i=0;i<4;i++){ cli_write_int(src_ip->bytes[i]); if(i<3) cli_write("."); }
|
FAT32_FileHandle *fh = fat32_open("messages", "a");
|
||||||
cli_write(":"); cli_write_int(src_port); cli_write(" ");
|
if (fh) {
|
||||||
for(size_t i=0;i<length;i++){ cli_putchar(((const char*)data)[i]); }
|
char buf[32];
|
||||||
cli_write("\n");
|
fat32_write(fh, "UDP from ", 9);
|
||||||
|
|
||||||
|
// Write IP
|
||||||
|
for(int i=0;i<4;i++){
|
||||||
|
cli_itoa(src_ip->bytes[i], buf);
|
||||||
|
fat32_write(fh, buf, cli_strlen(buf));
|
||||||
|
if(i<3) fat32_write(fh, ".", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
fat32_write(fh, ":", 1);
|
||||||
|
|
||||||
|
// Write Port
|
||||||
|
cli_itoa(src_port, buf);
|
||||||
|
fat32_write(fh, buf, cli_strlen(buf));
|
||||||
|
|
||||||
|
fat32_write(fh, " ", 1);
|
||||||
|
|
||||||
|
// Write Message
|
||||||
|
fat32_write(fh, data, length);
|
||||||
|
fat32_write(fh, "\n", 1);
|
||||||
|
|
||||||
|
fat32_close(fh);
|
||||||
|
|
||||||
|
cmd_increment_msg_count();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cli_cmd_udptest(char *args){
|
void cli_cmd_udptest(char *args){
|
||||||
|
|
@ -110,3 +137,54 @@ void cli_cmd_udptest(char *args){
|
||||||
if(port<=0||port>65535){ cli_write("Invalid port\n"); return; }
|
if(port<=0||port>65535){ cli_write("Invalid port\n"); return; }
|
||||||
if(udp_register_callback((uint16_t)port,udp_print_callback)==0) cli_write("UDP callback registered\n"); else cli_write("Register failed\n");
|
if(udp_register_callback((uint16_t)port,udp_print_callback)==0) cli_write("UDP callback registered\n"); else cli_write("Register failed\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cli_cmd_msgrc(char *args) {
|
||||||
|
(void)args;
|
||||||
|
// Reset message count since we are viewing them
|
||||||
|
cmd_reset_msg_count();
|
||||||
|
|
||||||
|
FAT32_FileHandle *fh = fat32_open("messages", "r");
|
||||||
|
if (!fh) {
|
||||||
|
cli_write("No messages.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t size = fh->size;
|
||||||
|
if (size == 0) {
|
||||||
|
fat32_close(fh);
|
||||||
|
cli_write("No messages.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *buffer = (char*)kmalloc(size + 1);
|
||||||
|
if (!buffer) {
|
||||||
|
fat32_close(fh);
|
||||||
|
cli_write("Error: Out of memory\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fat32_read(fh, buffer, size);
|
||||||
|
buffer[size] = 0;
|
||||||
|
fat32_close(fh);
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
int pos = size - 1;
|
||||||
|
|
||||||
|
while (count < 10 && pos >= 0) {
|
||||||
|
// Skip trailing newlines/whitespace
|
||||||
|
while (pos >= 0 && (buffer[pos] == '\n' || buffer[pos] == '\r')) {
|
||||||
|
buffer[pos] = 0;
|
||||||
|
pos--;
|
||||||
|
}
|
||||||
|
if (pos < 0) break;
|
||||||
|
|
||||||
|
// Find start of line
|
||||||
|
while (pos >= 0 && buffer[pos] != '\n' && buffer[pos] != '\r') pos--;
|
||||||
|
|
||||||
|
cli_write(&buffer[pos + 1]);
|
||||||
|
cli_write("\n");
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
kfree(buffer);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,17 @@ static char pipe_buffer[8192];
|
||||||
static int pipe_buffer_pos = 0;
|
static int pipe_buffer_pos = 0;
|
||||||
int boot_year, boot_month, boot_day, boot_hour, boot_min, boot_sec;
|
int boot_year, boot_month, boot_day, boot_hour, boot_min, boot_sec;
|
||||||
|
|
||||||
|
// Message notification state
|
||||||
|
static int msg_count = 0;
|
||||||
|
|
||||||
|
void cmd_increment_msg_count(void) {
|
||||||
|
msg_count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void cmd_reset_msg_count(void) {
|
||||||
|
msg_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// --- Helpers ---
|
// --- Helpers ---
|
||||||
static void cmd_memset(void *dest, int val, size_t len) {
|
static void cmd_memset(void *dest, int val, size_t len) {
|
||||||
unsigned char *ptr = dest;
|
unsigned char *ptr = dest;
|
||||||
|
|
@ -481,6 +492,8 @@ static const CommandEntry commands[] = {
|
||||||
{"udptest", cli_cmd_udptest},
|
{"udptest", cli_cmd_udptest},
|
||||||
{"PCILIST", cli_cmd_pcilist},
|
{"PCILIST", cli_cmd_pcilist},
|
||||||
{"pcilist", cli_cmd_pcilist},
|
{"pcilist", cli_cmd_pcilist},
|
||||||
|
{"MSGRC", cli_cmd_msgrc},
|
||||||
|
{"msgrc", cli_cmd_msgrc},
|
||||||
{"COMPC", cli_cmd_cc},
|
{"COMPC", cli_cmd_cc},
|
||||||
{"compc", cli_cmd_cc},
|
{"compc", cli_cmd_cc},
|
||||||
{"CC", cli_cmd_cc},
|
{"CC", cli_cmd_cc},
|
||||||
|
|
@ -941,6 +954,11 @@ void cmd_reset(void) {
|
||||||
// Reset terminal to fresh state
|
// Reset terminal to fresh state
|
||||||
cmd_screen_clear();
|
cmd_screen_clear();
|
||||||
cmd_write("BrewOS Command Prompt\n");
|
cmd_write("BrewOS Command Prompt\n");
|
||||||
|
if (msg_count > 0) {
|
||||||
|
cmd_write("You have ");
|
||||||
|
cmd_write_int(msg_count);
|
||||||
|
cmd_write(" new message(s) run \"msgrc\" to see your new message(s).\n");
|
||||||
|
}
|
||||||
cmd_write(PROMPT);
|
cmd_write(PROMPT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1046,6 +1064,15 @@ static void create_test_files(void) {
|
||||||
fat32_close(fh);
|
fat32_close(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fh = fat32_open("Apps/README.md", "w");
|
||||||
|
if (fh) {
|
||||||
|
const char *content =
|
||||||
|
"# All compiled C files in this directory are openable from any other directory by typing in the name of the compiled file by typing in the name of the compiled file.\n\n"
|
||||||
|
"The c file 'wordofgod.c' contains a C program similar to one in TempleOS, which Terry A. Davis (RIP) saw as 'words from god' telling him what to do with his kernel.\n"
|
||||||
|
"I made this file as a tribute to him, as he also inspired me to create this project in '24. If you want to run it you simply do cc (or compc) wordofgod.c and then run ./wordofgod \n";
|
||||||
|
fat32_write(fh, (void *)content, cmd_strlen(content));
|
||||||
|
fat32_close(fh);
|
||||||
|
}
|
||||||
write_license_file();
|
write_license_file();
|
||||||
|
|
||||||
fh = fat32_open("Documents/notes.txt", "w");
|
fh = fat32_open("Documents/notes.txt", "w");
|
||||||
|
|
@ -1061,6 +1088,7 @@ static void create_test_files(void) {
|
||||||
fat32_write(fh, (void *)content, 32);
|
fat32_write(fh, (void *)content, 32);
|
||||||
fat32_close(fh);
|
fat32_close(fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fh = fat32_open("Apps/wordofgod.c", "w");
|
fh = fat32_open("Apps/wordofgod.c", "w");
|
||||||
if (fh) {
|
if (fh) {
|
||||||
|
|
|
||||||
|
|
@ -14,4 +14,7 @@ void cmd_putchar(char c);
|
||||||
void cmd_write_int(int n);
|
void cmd_write_int(int n);
|
||||||
void cmd_screen_clear(void);
|
void cmd_screen_clear(void);
|
||||||
|
|
||||||
|
void cmd_increment_msg_count(void);
|
||||||
|
void cmd_reset_msg_count(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -312,8 +312,10 @@ static void editor_paint(Window *win) {
|
||||||
int text_len = lines[line_idx].length;
|
int text_len = lines[line_idx].length;
|
||||||
int char_idx = 0;
|
int char_idx = 0;
|
||||||
int local_display_line = 0;
|
int local_display_line = 0;
|
||||||
|
bool first_pass = true;
|
||||||
|
|
||||||
while (char_idx < text_len && display_line < max_display_lines) {
|
while ((char_idx < text_len || (text_len == 0 && first_pass)) && display_line < max_display_lines) {
|
||||||
|
first_pass = false;
|
||||||
int current_display_y = offset_y + 35 + display_line * EDITOR_LINE_HEIGHT;
|
int current_display_y = offset_y + 35 + display_line * EDITOR_LINE_HEIGHT;
|
||||||
|
|
||||||
// Extract segment (up to max_chars_per_line)
|
// Extract segment (up to max_chars_per_line)
|
||||||
|
|
@ -353,9 +355,18 @@ static void editor_paint(Window *win) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw cursor if on this line and wrapped segment
|
// Draw cursor if on this line and wrapped segment
|
||||||
if (line_idx == cursor_line && cursor_col >= segment_start && cursor_col < segment_start + segment_len) {
|
if (line_idx == cursor_line) {
|
||||||
int cursor_x = text_start_x + ((cursor_col - segment_start) * EDITOR_CHAR_WIDTH);
|
int segment_end = segment_start + segment_len;
|
||||||
draw_rect(cursor_x, current_display_y, 2, 10, COLOR_BLACK);
|
bool draw_cursor = false;
|
||||||
|
if (cursor_col >= segment_start && cursor_col < segment_end) {
|
||||||
|
draw_cursor = true;
|
||||||
|
} else if (cursor_col == text_len && segment_end == text_len) {
|
||||||
|
draw_cursor = true;
|
||||||
|
}
|
||||||
|
if (draw_cursor) {
|
||||||
|
int cursor_x = text_start_x + ((cursor_col - segment_start) * EDITOR_CHAR_WIDTH);
|
||||||
|
draw_rect(cursor_x, current_display_y, 2, 10, COLOR_BLACK);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display_line++;
|
display_line++;
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,11 @@ void network_process_frames(void){
|
||||||
if(for_our_ip || ip->dest_ip[0]==255){
|
if(for_our_ip || ip->dest_ip[0]==255){
|
||||||
mac_address_t src_mac;
|
mac_address_t src_mac;
|
||||||
kmemcpy(src_mac.bytes,eth->src_mac,6);
|
kmemcpy(src_mac.bytes,eth->src_mac,6);
|
||||||
|
|
||||||
|
ipv4_address_t src_ip_struct;
|
||||||
|
kmemcpy(src_ip_struct.bytes, ip->src_ip, 4);
|
||||||
|
arp_cache_add(&src_ip_struct, &src_mac);
|
||||||
|
|
||||||
ipv4_process_packet(ip,&src_mac,payload_length);
|
ipv4_process_packet(ip,&src_mac,payload_length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -377,6 +377,7 @@ void wm_handle_click(int x, int y) {
|
||||||
if (y < menu_y + 25) { // Explorer
|
if (y < menu_y + 25) { // Explorer
|
||||||
win_explorer.visible = true;
|
win_explorer.visible = true;
|
||||||
win_explorer.focused = true;
|
win_explorer.focused = true;
|
||||||
|
explorer_reset();
|
||||||
// Bring to front
|
// Bring to front
|
||||||
int max_z = 0;
|
int max_z = 0;
|
||||||
for (int i = 0; i < window_count; i++) {
|
for (int i = 0; i < window_count; i++) {
|
||||||
|
|
@ -411,6 +412,7 @@ void wm_handle_click(int x, int y) {
|
||||||
} else if (y < menu_y + 85) { // CMD
|
} else if (y < menu_y + 85) { // CMD
|
||||||
win_cmd.visible = true;
|
win_cmd.visible = true;
|
||||||
win_cmd.focused = true;
|
win_cmd.focused = true;
|
||||||
|
cmd_reset();
|
||||||
int max_z = 0;
|
int max_z = 0;
|
||||||
for (int i = 0; i < window_count; i++) {
|
for (int i = 0; i < window_count; i++) {
|
||||||
if (all_windows[i]->z_index > max_z) {
|
if (all_windows[i]->z_index > max_z) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue