mirror of
https://github.com/BoredDevNL/BoredOS.git
synced 2026-05-15 10:48:38 +00:00
Network fix
This commit is contained in:
parent
cb4edb6264
commit
8afb488539
13 changed files with 77 additions and 23 deletions
BIN
boredos.iso
BIN
boredos.iso
Binary file not shown.
BIN
build/idt.o
BIN
build/idt.o
Binary file not shown.
|
|
@ -3,25 +3,14 @@
|
|||
// This header needs to maintain in any file it is present in, as per the GPL license terms.
|
||||
#include "idt.h"
|
||||
#include "io.h"
|
||||
#include "kutils.h"
|
||||
|
||||
extern void serial_write(const char *str);
|
||||
|
||||
// Simple hex printer for debugging
|
||||
static void print_hex(uint64_t val) {
|
||||
const char* digits = "0123456789ABCDEF";
|
||||
char buf[17];
|
||||
buf[16] = '\0';
|
||||
for (int i = 15; i >= 0; i--) {
|
||||
buf[i] = digits[val & 0xF];
|
||||
val >>= 4;
|
||||
}
|
||||
serial_write("0x");
|
||||
serial_write(buf);
|
||||
}
|
||||
|
||||
#include "process.h"
|
||||
#include "cmd.h"
|
||||
|
||||
|
||||
void kernel_panic(registers_t *regs, const char *error_name);
|
||||
|
||||
static const char *exception_messages[] = {
|
||||
|
|
@ -61,10 +50,13 @@ static const char *exception_messages[] = {
|
|||
|
||||
uint64_t exception_handler_c(registers_t *regs) {
|
||||
uint64_t vector = regs->int_no;
|
||||
char buf[17];
|
||||
|
||||
// Serial Mirror
|
||||
serial_write("\n*** EXCEPTION ***\nVector: ");
|
||||
print_hex(vector);
|
||||
k_itoa_hex(vector, buf);
|
||||
serial_write("0x");
|
||||
serial_write(buf);
|
||||
|
||||
if ((regs->cs & 0x3) != 0) {
|
||||
serial_write("\nUSER MODE EXCEPTION - Terminating process.\n");
|
||||
|
|
|
|||
|
|
@ -66,6 +66,26 @@ void k_itoa(int n, char *buf) {
|
|||
}
|
||||
}
|
||||
|
||||
void k_itoa_hex(uint64_t n, char *buf) {
|
||||
const char *digits = "0123456789ABCDEF";
|
||||
if (n == 0) {
|
||||
buf[0] = '0';
|
||||
buf[1] = 0;
|
||||
return;
|
||||
}
|
||||
int i = 0;
|
||||
while (n > 0) {
|
||||
buf[i++] = digits[n & 0xF];
|
||||
n >>= 4;
|
||||
}
|
||||
buf[i] = 0;
|
||||
for (int j = 0; j < i / 2; j++) {
|
||||
char t = buf[j];
|
||||
buf[j] = buf[i - 1 - j];
|
||||
buf[i - 1 - j] = t;
|
||||
}
|
||||
}
|
||||
|
||||
void k_delay(int iterations) {
|
||||
for (volatile int i = 0; i < iterations; i++) {
|
||||
__asm__ __volatile__("nop");
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ int k_strcmp(const char *s1, const char *s2);
|
|||
void k_strcpy(char *dest, const char *src);
|
||||
int k_atoi(const char *str);
|
||||
void k_itoa(int n, char *buf);
|
||||
void k_itoa_hex(uint64_t n, char *buf);
|
||||
|
||||
// Kernel timing utilities
|
||||
void k_delay(int iterations);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "net_defs.h"
|
||||
|
||||
static int network_initialized = 0;
|
||||
static int has_ip = 0;
|
||||
static mac_address_t our_mac;
|
||||
static ipv4_address_t ip_address = {{0,0,0,0}};
|
||||
static ipv4_address_t gateway_ip = {{0,0,0,0}};
|
||||
|
|
@ -68,7 +69,8 @@ int network_get_mac_address(mac_address_t* mac){
|
|||
}
|
||||
|
||||
int network_get_ipv4_address(ipv4_address_t* ip){ if(!network_initialized) return -1; *ip=ip_address; return 0; }
|
||||
int network_set_ipv4_address(const ipv4_address_t* ip){ if(!network_initialized) return -1; ip_address=*ip; return 0; }
|
||||
int network_set_ipv4_address(const ipv4_address_t* ip){ if(!network_initialized) return -1; ip_address=*ip; has_ip = 1; return 0; }
|
||||
int network_has_ip(void) { return has_ip; }
|
||||
|
||||
int network_get_gateway_ip(ipv4_address_t* ip){ if(!network_initialized) return -1; *ip=gateway_ip; return 0; }
|
||||
int network_get_dns_ip(ipv4_address_t* ip){ if(!network_initialized) return -1; *ip=dns_server_ip; return 0; }
|
||||
|
|
@ -485,6 +487,7 @@ static void dhcp_udp_callback(const ipv4_address_t* src_ip,uint16_t src_port,con
|
|||
p+=l;
|
||||
}
|
||||
|
||||
has_ip = 1;
|
||||
dhcp_state=2;
|
||||
} else if(mtype==DHCP_MSG_NAK){
|
||||
dhcp_state=-1;
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ int udp_send_packet_to_mac(const ipv4_address_t* dest_ip, const mac_address_t* d
|
|||
typedef void (*udp_callback_t)(const ipv4_address_t* src_ip, uint16_t src_port, const mac_address_t* src_mac, const void* data, size_t length);
|
||||
int udp_register_callback(uint16_t port, udp_callback_t callback);
|
||||
int network_is_initialized(void);
|
||||
int network_has_ip(void);
|
||||
int network_get_frames_received(void);
|
||||
int network_get_udp_packets_received(void);
|
||||
int network_get_udp_callbacks_called(void);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
#include "process.h"
|
||||
#include "graphics.h"
|
||||
#include "io.h"
|
||||
#include "kutils.h"
|
||||
|
||||
extern void serial_write(const char *str);
|
||||
|
||||
|
|
@ -108,10 +109,35 @@ void kernel_panic(registers_t *regs, const char *error_name) {
|
|||
graphics_mark_screen_dirty();
|
||||
graphics_flip_buffer();
|
||||
|
||||
char hex_buf[17];
|
||||
serial_write("\n*** KERNEL PANIC ***\n");
|
||||
serial_write(error_name);
|
||||
serial_write("\n");
|
||||
|
||||
serial_write("Vector: 0x");
|
||||
k_itoa_hex(regs->int_no, hex_buf);
|
||||
serial_write(hex_buf);
|
||||
serial_write("\n");
|
||||
|
||||
serial_write("Error Code: 0x");
|
||||
k_itoa_hex(regs->err_code, hex_buf);
|
||||
serial_write(hex_buf);
|
||||
serial_write("\n");
|
||||
|
||||
serial_write("RIP: 0x");
|
||||
k_itoa_hex(regs->rip, hex_buf);
|
||||
serial_write(hex_buf);
|
||||
serial_write("\n");
|
||||
|
||||
if (regs->int_no == 14) {
|
||||
uint64_t cr2;
|
||||
asm volatile("mov %%cr2, %0" : "=r"(cr2));
|
||||
serial_write("CR2: 0x");
|
||||
k_itoa_hex(cr2, hex_buf);
|
||||
serial_write(hex_buf);
|
||||
serial_write("\n");
|
||||
}
|
||||
|
||||
// Halt
|
||||
while(1) {
|
||||
asm volatile("cli; hlt");
|
||||
|
|
|
|||
|
|
@ -723,6 +723,8 @@ uint64_t syscall_handler_c(uint64_t syscall_num, uint64_t arg1, uint64_t arg2, u
|
|||
return cli_cmd_ping_syscall(dest_ip);
|
||||
} else if (cmd == 27) { // SYSTEM_CMD_NETWORK_IS_INIT
|
||||
return network_is_initialized() ? 1 : 0;
|
||||
} else if (cmd == 30) { // SYSTEM_CMD_NETWORK_HAS_IP
|
||||
return network_has_ip() ? 1 : 0;
|
||||
} else if (cmd == 28) { // SYSTEM_CMD_GET_SHELL_CONFIG
|
||||
const char *key = (const char *)arg2;
|
||||
if (!key) return -1;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,6 @@ static void about_paint(ui_window_t win) {
|
|||
int w = 185;
|
||||
int h = 240;
|
||||
|
||||
//ui_draw_rect(win, 0, 0, w, h, 0xFF1E1E1E);
|
||||
|
||||
int offset_x = 15;
|
||||
int offset_y = 35;
|
||||
|
|
|
|||
|
|
@ -179,6 +179,10 @@ int sys_network_is_initialized(void) {
|
|||
return (int)syscall2(SYS_SYSTEM, SYSTEM_CMD_NETWORK_IS_INIT, 0);
|
||||
}
|
||||
|
||||
int sys_network_has_ip(void) {
|
||||
return (int)syscall2(SYS_SYSTEM, SYSTEM_CMD_NETWORK_HAS_IP, 0);
|
||||
}
|
||||
|
||||
uint64_t sys_get_shell_config(const char *key) {
|
||||
return (uint64_t)sys_system(SYSTEM_CMD_GET_SHELL_CONFIG, (uint64_t)key, 0, 0, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
#define SYSTEM_CMD_NETWORK_GET_DNS 25
|
||||
#define SYSTEM_CMD_ICMP_PING 26
|
||||
#define SYSTEM_CMD_NETWORK_IS_INIT 27
|
||||
#define SYSTEM_CMD_NETWORK_HAS_IP 30
|
||||
#define SYSTEM_CMD_GET_SHELL_CONFIG 28
|
||||
#define SYSTEM_CMD_SET_TEXT_COLOR 29
|
||||
|
||||
|
|
@ -114,8 +115,9 @@ int sys_network_get_dns(net_ipv4_address_t *ip);
|
|||
int sys_udp_send(const net_ipv4_address_t *dest_ip, uint16_t dest_port, uint16_t src_port, const void *data, size_t data_len);
|
||||
int sys_icmp_ping(const net_ipv4_address_t *dest_ip);
|
||||
int sys_network_is_initialized(void);
|
||||
|
||||
int sys_network_has_ip(void);
|
||||
uint64_t sys_get_shell_config(const char *key);
|
||||
void sys_set_text_color(uint32_t color);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -74,13 +74,17 @@ static void cmd_netinfo(void) {
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
if (sys_network_get_ip(&ip) == 0) {
|
||||
printf("IP: ");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("%d", ip.bytes[i]);
|
||||
if (i < 3) printf(".");
|
||||
if (sys_network_has_ip()) {
|
||||
if (sys_network_get_ip(&ip) == 0) {
|
||||
printf("IP: ");
|
||||
for (int i = 0; i < 4; i++) {
|
||||
printf("%d", ip.bytes[i]);
|
||||
if (i < 3) printf(".");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
printf("IP: Not assigned\n");
|
||||
}
|
||||
|
||||
printf("Frames: %d\n", sys_network_get_stat(0));
|
||||
|
|
|
|||
Loading…
Reference in a new issue