feat: e100e Ethernet driver, ramdisk reorganization, shell rewrite, web server/client, and more
This commit is contained in:
@@ -48,8 +48,23 @@ namespace Zenith {
|
||||
static constexpr uint64_t SYS_SEND = 34;
|
||||
static constexpr uint64_t SYS_RECV = 35;
|
||||
static constexpr uint64_t SYS_CLOSESOCK = 36;
|
||||
static constexpr uint64_t SYS_GETNETCFG = 37;
|
||||
static constexpr uint64_t SYS_SETNETCFG = 38;
|
||||
static constexpr uint64_t SYS_SENDTO = 39;
|
||||
static constexpr uint64_t SYS_RECVFROM = 40;
|
||||
static constexpr uint64_t SYS_FWRITE = 41;
|
||||
static constexpr uint64_t SYS_FCREATE = 42;
|
||||
|
||||
static constexpr int SOCK_TCP = 1;
|
||||
static constexpr int SOCK_UDP = 2;
|
||||
|
||||
struct NetCfg {
|
||||
uint32_t ipAddress; // network byte order
|
||||
uint32_t subnetMask; // network byte order
|
||||
uint32_t gateway; // network byte order
|
||||
uint8_t macAddress[6];
|
||||
uint8_t _pad[2];
|
||||
};
|
||||
|
||||
struct DateTime {
|
||||
uint16_t Year;
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* string.h
|
||||
* Common string and memory utility functions for ZenithOS programs
|
||||
* Copyright (c) 2025-2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace zenith {
|
||||
|
||||
inline int slen(const char* s) {
|
||||
int n = 0;
|
||||
while (s[n]) n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
inline bool streq(const char* a, const char* b) {
|
||||
while (*a && *b) {
|
||||
if (*a != *b) return false;
|
||||
a++; b++;
|
||||
}
|
||||
return *a == *b;
|
||||
}
|
||||
|
||||
inline bool starts_with(const char* str, const char* prefix) {
|
||||
while (*prefix) {
|
||||
if (*str != *prefix) return false;
|
||||
str++; prefix++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline const char* skip_spaces(const char* s) {
|
||||
while (*s == ' ') s++;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline void memcpy(void* dst, const void* src, uint64_t n) {
|
||||
auto* d = (uint8_t*)dst;
|
||||
auto* s = (const uint8_t*)src;
|
||||
for (uint64_t i = 0; i < n; i++) d[i] = s[i];
|
||||
}
|
||||
|
||||
inline void memmove(void* dst, const void* src, uint64_t n) {
|
||||
auto* d = (uint8_t*)dst;
|
||||
auto* s = (const uint8_t*)src;
|
||||
if (d < s) {
|
||||
for (uint64_t i = 0; i < n; i++) d[i] = s[i];
|
||||
} else {
|
||||
for (uint64_t i = n; i > 0; i--) d[i-1] = s[i-1];
|
||||
}
|
||||
}
|
||||
|
||||
inline void memset(void* dst, int val, uint64_t n) {
|
||||
auto* d = (uint8_t*)dst;
|
||||
for (uint64_t i = 0; i < n; i++) d[i] = (uint8_t)val;
|
||||
}
|
||||
|
||||
inline void strcpy(char* dst, const char* src) {
|
||||
while (*src) *dst++ = *src++;
|
||||
*dst = '\0';
|
||||
}
|
||||
|
||||
inline void strncpy(char* dst, const char* src, int max) {
|
||||
int i = 0;
|
||||
while (src[i] && i < max - 1) { dst[i] = src[i]; i++; }
|
||||
dst[i] = '\0';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -136,6 +136,14 @@ namespace zenith {
|
||||
return (int)syscall3(Zenith::SYS_READDIR, (uint64_t)path, (uint64_t)names, (uint64_t)max);
|
||||
}
|
||||
|
||||
// File write/create
|
||||
inline int fwrite(int handle, const uint8_t* buf, uint64_t off, uint64_t size) {
|
||||
return (int)syscall4(Zenith::SYS_FWRITE, (uint64_t)handle, (uint64_t)buf, off, size);
|
||||
}
|
||||
inline int fcreate(const char* path) {
|
||||
return (int)syscall1(Zenith::SYS_FCREATE, (uint64_t)path);
|
||||
}
|
||||
|
||||
// Memory
|
||||
inline void* alloc(uint64_t size) { return (void*)syscall1(Zenith::SYS_ALLOC, size); }
|
||||
inline void free(void* ptr) { syscall1(Zenith::SYS_FREE, (uint64_t)ptr); }
|
||||
@@ -157,6 +165,10 @@ namespace zenith {
|
||||
return (int32_t)syscall2(Zenith::SYS_PING, (uint64_t)ip, (uint64_t)timeoutMs);
|
||||
}
|
||||
|
||||
// Network configuration
|
||||
inline void get_netcfg(Zenith::NetCfg* out) { syscall1(Zenith::SYS_GETNETCFG, (uint64_t)out); }
|
||||
inline int set_netcfg(const Zenith::NetCfg* cfg) { return (int)syscall1(Zenith::SYS_SETNETCFG, (uint64_t)cfg); }
|
||||
|
||||
// Sockets
|
||||
inline int socket(int type) {
|
||||
return (int)syscall1(Zenith::SYS_SOCKET, (uint64_t)type);
|
||||
@@ -182,6 +194,14 @@ namespace zenith {
|
||||
inline int closesocket(int fd) {
|
||||
return (int)syscall1(Zenith::SYS_CLOSESOCK, (uint64_t)fd);
|
||||
}
|
||||
inline int sendto(int fd, const void* data, uint32_t len, uint32_t destIp, uint16_t destPort) {
|
||||
return (int)syscall5(Zenith::SYS_SENDTO, (uint64_t)fd, (uint64_t)data,
|
||||
(uint64_t)len, (uint64_t)destIp, (uint64_t)destPort);
|
||||
}
|
||||
inline int recvfrom(int fd, void* buf, uint32_t maxLen, uint32_t* srcIp, uint16_t* srcPort) {
|
||||
return (int)syscall5(Zenith::SYS_RECVFROM, (uint64_t)fd, (uint64_t)buf,
|
||||
(uint64_t)maxLen, (uint64_t)srcIp, (uint64_t)srcPort);
|
||||
}
|
||||
|
||||
// Process management
|
||||
inline void waitpid(int pid) { syscall1(Zenith::SYS_WAITPID, (uint64_t)pid); }
|
||||
|
||||
Reference in New Issue
Block a user