some progress on dos vesa, but not quite

This commit is contained in:
veclavtlica committed 2026-10-31 14:15:49 +03:00
1 parent 55ac075e4d
commit 4998fafef9
11 files changed
+342 -180

No files matched your search

+1 -1
View File
@@ -126,7 +126,7 @@ void com_std_print_(int32_t start, ...) {
} while (type != '.');
com_std_write(COM_STD_OUTFD, "\n", 1);
com_std_write(COM_STD_OUTFD, "\n\r", 2);
va_end(args);
}
+80
View File
@@ -0,0 +1,80 @@
#include "../std.h"
#include <assert.h>
#include <stdarg.h>
#include <stdint.h>
#include "any.c"
#include "nolibc.c"
// void *com_std_alloc(void *ptr, size_t size) {
// return size != 0 ? realloc(ptr, size) : (free(ptr), NULL);
// }
// double com_std_sqrt(double v) { return sqrt(v); }
// double com_std_fabs(double v) { return fabs(v); }
// double com_std_sin(double v) { return sin(v); }
// double com_std_cos(double v) { return cos(v); }
// com_std_fd com_std_open(char const *path, uint32_t flags) {
// com_std_assert(flags != 0);
// char *mode = flags & COM_STD_OPEN_READ && flags & COM_STD_OPEN_WRITE ? "r+"
// : flags & COM_STD_OPEN_READ ? "r"
// : "w";
// return fopen(path, mode);
// }
bool com_std_write(com_std_fd fd, void const *data, uint32_t bytes) {
uint32_t written;
bool carry_clear;
__asm__ volatile("int $0x21"
: "=a"(written), "=@ccnc"(carry_clear)
: "a"(0x4000), "b"(fd), "c"(bytes), "d"(data)
: "memory", "cc");
return !carry_clear && written == bytes;
}
// int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto) {
// com_std_assert(data != NULL && upto != 0);
// return fread(data, 1, upto, fd);
// }
// bool com_std_has_data(com_std_fd fd) {
// struct pollfd pfd = {.fd = (intptr_t)fd, .events = POLLIN};
// int ret = poll(&pfd, 1, 0);
// if (ret > 0) {
// return pfd.revents & POLLIN;
// } else
// return false;
// }
// bool com_std_sfwd(com_std_fd fd, uint32_t bytes) {
// com_std_assert(fd != NULL && bytes != 0);
// return fseek(fd, bytes, SEEK_CUR) == 0;
// }
// com_std_fd com_std_socket(bool isnetwork) {
// if (!isnetwork) {
// int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
// return fdopen(sockfd, "w+b");
// } else
// return NULL;
// }
// bool com_std_connect(com_std_fd fd, bool isnetwork, char const *address) {
// com_std_assert(address != NULL);
// if (!isnetwork) {
// struct sockaddr_un addr = {.sun_family = AF_UNIX};
// __builtin_memcpy(&addr.sun_path, address, com_str_ext_len(address));
// return connect(fileno(fd), (struct sockaddr *)&addr, sizeof(addr)) == 0;
// } else
// return NULL;
// }
void com_std_exit(int32_t status) {
(void)status;
__asm__ volatile("int $0x21" ::"a"(0x4c00 | (status & 0xff))
: "memory", "cc");
__builtin_unreachable();
}
// void com_std_close(com_std_fd fd) { fclose(fd); }
+1 -1
View File
@@ -48,7 +48,7 @@ void sincos(double v, double *s, double *c) {
double sqrt(double v) {
double r;
__asm__ volatile("sqrtss %1, %0" : "=x"(r) : "x"(v));
__asm__ volatile("rsqrtss %1, %0" : "=x"(r) : "x"(v));
return r;
}
+9 -3
View File
@@ -21,19 +21,25 @@
#define COM_DEF_TARGET_LINUX 1
#define COM_DEF_TARGET_WASM 2
#define COM_DEF_TARGET_COSMO 3
#define COM_DEF_TARGET_DOS 4
#ifndef COM_DEF_TARGET
#if defined(__wasm__)
#define COM_DEF_TARGET COM_DEF_TARGET_WASM
#define com_def_export_sym(m_s) __attribute__((export_name(m_s)))
#elif defined(__linux__)
#define COM_DEF_TARGET COM_DEF_TARGET_LINUX
#define com_def_export_sym(m_s) __attribute__((visibility("default")))
#elif defined(__COSMOPOLITAN__)
#define COM_DEF_TARGET COM_DEF_TARGET_COSMO
#define com_def_export_sym(m_s) __attribute__((visibility("default")))
#else
#error Unknown target.
#endif
#endif
#if COM_DEF_TARGET == COM_DEF_TARGET_WASM
#define com_def_export_sym(m_s) __attribute__((export_name(m_s)))
#else
#define com_def_export_sym(m_s) __attribute__((visibility("default")))
#endif
#define COM_DEF_CPU_AMD64 1
#define COM_DEF_CPU_X86 2
+6 -3
View File
@@ -3,6 +3,8 @@
even memory mnagement.
*/
/* TODO: Split into io.h and math.h */
#ifndef COM_STD_H
#define COM_STD_H
@@ -69,6 +71,9 @@ void com_std_print_(int32_t start, ...);
#define com_std_print(...) com_std_print_(__VA_ARGS__, '.')
void com_std_print_str(char const *str, uint32_t len, bool newline);
/* Note: Functions listed below are only available for dev builds. */
/* Trigonometry functions are for reference testing of our own fixed point
* implementations. Do not use otherwise. */
#define COM_STD_PIF ((float)3.14159265358979323846)
double com_std_sqrt(double v);
@@ -76,9 +81,7 @@ double com_std_fabs(double v);
double com_std_sin(double v);
double com_std_cos(double v);
/* Note: Functions listed below are only available for dev builds. */
/* Trigonometry functions are for reference testing of our own fixed point
* implementations. Do not use otherwise. */
/* TODO: Move to def.h? or just asrt.h? */
#define com_std_assert(p_h) \
do { \
if (!(p_h)) { \
+8 -1
View File
@@ -24,12 +24,19 @@ typedef struct com_str {
uint32_t len;
uint32_t flags;
char data[] __attribute__((aligned(COM_DEF_ALIGNMENT)));
} com_str;
/* NOTE: Have to be moved to static or global memory. */
#define com_str_lit(p_l) {NULL, sizeof(p_l) - 1, COM_STR_NULL_TERMINATED, (p_l)}
static inline void com_str_copy_to_mem(struct com_str *s, char *to,
bool withnull) {
for (int i = 0; i < s->len; ++i)
to[i] = s->data[i];
if (withnull)
to[s->len] = '\0';
}
static inline uint32_t com_str_ext_len(char const *s) {
char const *p = s;
for (; *p != 0; ++p) {