feat: native .opc executable binary format, hardware PCI GPU driver, terminal text editor, and web browser
This commit is contained in:
@@ -57,6 +57,25 @@ typedef struct {
|
||||
uint16_t sequence;
|
||||
} icmp_hdr_t;
|
||||
|
||||
typedef struct {
|
||||
uint16_t src_port;
|
||||
uint16_t dst_port;
|
||||
uint32_t seq_num;
|
||||
uint32_t ack_num;
|
||||
uint8_t data_offset_reserved;
|
||||
uint8_t flags;
|
||||
uint16_t window_size;
|
||||
uint16_t checksum;
|
||||
uint16_t urgent_ptr;
|
||||
} tcp_hdr_t;
|
||||
|
||||
#define TCP_FLAG_FIN 0x01
|
||||
#define TCP_FLAG_SYN 0x02
|
||||
#define TCP_FLAG_RST 0x04
|
||||
#define TCP_FLAG_PSH 0x08
|
||||
#define TCP_FLAG_ACK 0x10
|
||||
#define TCP_FLAG_URG 0x20
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct {
|
||||
@@ -74,6 +93,7 @@ uint16_t net_checksum(const void *buf, size_t len);
|
||||
int net_send_arp_request(uint32_t target_ip);
|
||||
int net_send_icmp_ping(uint32_t target_ip, uint16_t seq);
|
||||
int net_poll_icmp_reply(uint32_t *from_ip, uint16_t *seq);
|
||||
int net_http_get(uint32_t target_ip, uint16_t port, const char *path, char *out_body, size_t max_body_len);
|
||||
uint32_t parse_ip(const char *str);
|
||||
void format_ip(uint32_t ip, char *buf);
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "stdint.h"
|
||||
|
||||
#define OPC_MAGIC 0x0143504F /* 'O', 'P', 'C', 0x01 */
|
||||
#define OPC_ARCH_X86_64 0x8664
|
||||
#define OPC_VERSION_1 1
|
||||
|
||||
/* Capability flags for OPC binaries */
|
||||
#define OPC_CAP_KERNEL_CTRL (1 << 0)
|
||||
#define OPC_CAP_UART (1 << 1)
|
||||
#define OPC_CAP_NET (1 << 2)
|
||||
#define OPC_CAP_FB (1 << 3)
|
||||
#define OPC_CAP_NOTIFY (1 << 4)
|
||||
#define OPC_CAP_ALL 0xFFFFFFFF
|
||||
|
||||
/* Segment flags */
|
||||
#define OPC_SEG_X (1 << 0) /* Executable */
|
||||
#define OPC_SEG_W (1 << 1) /* Writable */
|
||||
#define OPC_SEG_R (1 << 2) /* Readable */
|
||||
|
||||
#define OPC_SEG_TYPE_LOAD 1
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct opc_header {
|
||||
uint32_t magic; /* OPC_MAGIC ("OPC\x01") */
|
||||
uint16_t version; /* OPC_VERSION_1 */
|
||||
uint16_t arch; /* OPC_ARCH_X86_64 */
|
||||
uint64_t entry_rip; /* Virtual address of entry point */
|
||||
uint64_t stack_size; /* Required user stack size (bytes, e.g. 65536) */
|
||||
uint32_t caps_mask; /* Required capability bitmask */
|
||||
uint8_t preferred_core; /* Preferred CPU core (0..3, or 0xFF = any) */
|
||||
uint8_t num_segments; /* Number of opc_segment_t headers following */
|
||||
uint16_t reserved; /* Alignment padding */
|
||||
} __attribute__((packed)) opc_header_t;
|
||||
|
||||
typedef struct opc_segment {
|
||||
uint32_t seg_type; /* OPC_SEG_TYPE_LOAD */
|
||||
uint32_t flags; /* OPC_SEG_R | OPC_SEG_W | OPC_SEG_X */
|
||||
uint64_t file_offset; /* Offset within the .opc file */
|
||||
uint64_t vaddr; /* Target virtual address */
|
||||
uint64_t filesz; /* Size in file (bytes) */
|
||||
uint64_t memsz; /* Size in memory (bytes, memsz >= filesz, rest is BSS) */
|
||||
uint64_t align; /* Alignment requirement (usually 4096) */
|
||||
} __attribute__((packed)) opc_segment_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -29,6 +29,8 @@
|
||||
#define SYS_CPU_INFO 24 /* Query multi-core CPU core count and current core ID */
|
||||
#define SYS_NOTIFY_SEND 25 /* Post desktop notification to GUI compositor */
|
||||
#define SYS_NOTIFY_RECV 26 /* Poll pending desktop notifications non-blockingly */
|
||||
#define SYS_MODULE_EXEC 27 /* Find and execute boot module by name (.opc or .elf) */
|
||||
#define SYS_MODULE_LIST 28 /* List available boot modules in memory */
|
||||
|
||||
/* POSIX Process Signals */
|
||||
#define SIGHUP 1
|
||||
@@ -232,6 +234,21 @@ static inline sysret_t sys_log_debug(const char *msg, size_t len) {
|
||||
return (sysret_t)rax;
|
||||
}
|
||||
|
||||
static inline int64_t sys_module_exec(const char *name) {
|
||||
register uint64_t rax __asm__("rax") = SYS_MODULE_EXEC;
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)name;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi) : "rcx", "r11", "memory");
|
||||
return (int64_t)rax;
|
||||
}
|
||||
|
||||
static inline int sys_module_list(char *out_buf, size_t max_len) {
|
||||
register uint64_t rax __asm__("rax") = SYS_MODULE_LIST;
|
||||
register uint64_t rdi __asm__("rdi") = (uint64_t)out_buf;
|
||||
register uint64_t rsi __asm__("rsi") = (uint64_t)max_len;
|
||||
__asm__ volatile("syscall" : "+r"(rax) : "r"(rdi), "r"(rsi) : "rcx", "r11", "memory");
|
||||
return (int)rax;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user