mirror of
https://github.com/JannisHeydemann/BoredOS.git
synced 2026-05-30 02:16:58 +00:00
LwIP
This commit is contained in:
@@ -207,7 +207,6 @@ void puts(const char *s) {
|
||||
}
|
||||
|
||||
void printf(const char *fmt, ...) {
|
||||
// Simple printf implementation
|
||||
__builtin_va_list args;
|
||||
__builtin_va_start(args, fmt);
|
||||
char buf[1024];
|
||||
@@ -216,29 +215,56 @@ void printf(const char *fmt, ...) {
|
||||
while (*fmt) {
|
||||
if (*fmt == '%') {
|
||||
fmt++;
|
||||
// Flush current buffer
|
||||
if (buf_idx > 0) {
|
||||
sys_write(1, buf, buf_idx);
|
||||
buf_idx = 0;
|
||||
}
|
||||
|
||||
if (*fmt == 's') {
|
||||
char *s = __builtin_va_arg(args, char *);
|
||||
while (*s) buf[buf_idx++] = *s++;
|
||||
if (s) sys_write(1, s, strlen(s));
|
||||
else sys_write(1, "(null)", 6);
|
||||
} else if (*fmt == 'd') {
|
||||
int d = __builtin_va_arg(args, int);
|
||||
char ibuf[32];
|
||||
itoa(d, ibuf);
|
||||
char *s = ibuf;
|
||||
while (*s) buf[buf_idx++] = *s++;
|
||||
sys_write(1, ibuf, strlen(ibuf));
|
||||
} else if (*fmt == 'X' || *fmt == 'x') {
|
||||
uint32_t val = __builtin_va_arg(args, uint32_t);
|
||||
char xbuf[16];
|
||||
int xi = 0;
|
||||
if (val == 0) xbuf[xi++] = '0';
|
||||
else {
|
||||
while (val > 0) {
|
||||
uint32_t rem = val % 16;
|
||||
xbuf[xi++] = (rem < 10) ? (rem + '0') : (rem - 10 + 'A');
|
||||
val /= 16;
|
||||
}
|
||||
}
|
||||
while (xi > 0) {
|
||||
char c = xbuf[--xi];
|
||||
sys_write(1, &c, 1);
|
||||
}
|
||||
} else if (*fmt == 'c') {
|
||||
char c = (char)__builtin_va_arg(args, int);
|
||||
buf[buf_idx++] = c;
|
||||
sys_write(1, &c, 1);
|
||||
} else if (*fmt == '%') {
|
||||
buf[buf_idx++] = '%';
|
||||
char c = '%';
|
||||
sys_write(1, &c, 1);
|
||||
}
|
||||
} else {
|
||||
buf[buf_idx++] = *fmt;
|
||||
if (buf_idx >= 1024) {
|
||||
sys_write(1, buf, buf_idx);
|
||||
buf_idx = 0;
|
||||
}
|
||||
}
|
||||
fmt++;
|
||||
if (buf_idx >= 1022) break; // Simple overflow protection
|
||||
}
|
||||
buf[buf_idx] = 0;
|
||||
sys_write(1, buf, buf_idx);
|
||||
if (buf_idx > 0) {
|
||||
sys_write(1, buf, buf_idx);
|
||||
}
|
||||
__builtin_va_end(args);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,3 +195,31 @@ void sys_set_text_color(uint32_t color) {
|
||||
sys_system(SYSTEM_CMD_SET_TEXT_COLOR, (uint64_t)color, 0, 0, 0);
|
||||
}
|
||||
|
||||
int sys_tcp_connect(const net_ipv4_address_t *ip, uint16_t port) {
|
||||
return (int)syscall3(SYS_SYSTEM, SYSTEM_CMD_TCP_CONNECT, (uint64_t)ip, (uint64_t)port);
|
||||
}
|
||||
|
||||
int sys_tcp_send(const void *data, size_t len) {
|
||||
return (int)syscall3(SYS_SYSTEM, SYSTEM_CMD_TCP_SEND, (uint64_t)data, (uint64_t)len);
|
||||
}
|
||||
|
||||
int sys_tcp_recv(void *buf, size_t max_len) {
|
||||
return (int)syscall3(SYS_SYSTEM, SYSTEM_CMD_TCP_RECV, (uint64_t)buf, (uint64_t)max_len);
|
||||
}
|
||||
|
||||
int sys_tcp_close(void) {
|
||||
return (int)syscall2(SYS_SYSTEM, SYSTEM_CMD_TCP_CLOSE, 0);
|
||||
}
|
||||
|
||||
int sys_dns_lookup(const char *name, net_ipv4_address_t *out_ip) {
|
||||
return (int)syscall3(SYS_SYSTEM, SYSTEM_CMD_DNS_LOOKUP, (uint64_t)name, (uint64_t)out_ip);
|
||||
}
|
||||
|
||||
int sys_set_dns_server(const net_ipv4_address_t *ip) {
|
||||
return (int)syscall2(SYS_SYSTEM, SYSTEM_CMD_SET_DNS, (uint64_t)ip);
|
||||
}
|
||||
|
||||
void sys_network_force_unlock(void) {
|
||||
syscall2(SYS_SYSTEM, SYSTEM_CMD_NET_UNLOCK, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,13 @@
|
||||
#define SYSTEM_CMD_GET_SHELL_CONFIG 28
|
||||
#define SYSTEM_CMD_SET_TEXT_COLOR 29
|
||||
#define SYSTEM_CMD_SET_WALLPAPER_PATH 31
|
||||
#define SYSTEM_CMD_TCP_CONNECT 33
|
||||
#define SYSTEM_CMD_TCP_SEND 34
|
||||
#define SYSTEM_CMD_TCP_RECV 35
|
||||
#define SYSTEM_CMD_TCP_CLOSE 36
|
||||
#define SYSTEM_CMD_DNS_LOOKUP 37
|
||||
#define SYSTEM_CMD_SET_DNS 38
|
||||
#define SYSTEM_CMD_NET_UNLOCK 39
|
||||
|
||||
// Internal assembly entry into Ring 0
|
||||
extern uint64_t syscall0(uint64_t sys_num);
|
||||
@@ -122,5 +129,13 @@ int sys_network_has_ip(void);
|
||||
uint64_t sys_get_shell_config(const char *key);
|
||||
void sys_set_text_color(uint32_t color);
|
||||
|
||||
int sys_tcp_connect(const net_ipv4_address_t *ip, uint16_t port);
|
||||
int sys_tcp_send(const void *data, size_t len);
|
||||
int sys_tcp_recv(void *buf, size_t max_len);
|
||||
int sys_tcp_close(void);
|
||||
int sys_dns_lookup(const char *name, net_ipv4_address_t *out_ip);
|
||||
int sys_set_dns_server(const net_ipv4_address_t *ip);
|
||||
void sys_network_force_unlock(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user