Make it work on win32
This commit is contained in:
parent
07e262d8b8
commit
334866c209
220
getopt.c
Normal file
220
getopt.c
Normal file
@ -0,0 +1,220 @@
|
|||||||
|
#include <stddef.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include "getopt.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
char *optarg;
|
||||||
|
int optind=1, opterr=1, optopt, __optpos, optreset=0;
|
||||||
|
|
||||||
|
#define optpos __optpos
|
||||||
|
|
||||||
|
static void __getopt_msg(const char *a, const char *b, const char *c, size_t l)
|
||||||
|
{
|
||||||
|
FILE *f = stderr;
|
||||||
|
#if !defined(WIN32) && !defined(_WIN32)
|
||||||
|
flockfile(f);
|
||||||
|
#endif
|
||||||
|
fputs(a, f);
|
||||||
|
fwrite(b, strlen(b), 1, f);
|
||||||
|
fwrite(c, 1, l, f);
|
||||||
|
fputc('\n', f);
|
||||||
|
#if !defined(WIN32) && !defined(_WIN32)
|
||||||
|
funlockfile(f);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
int getopt(int argc, char * const argv[], const char *optstring)
|
||||||
|
{
|
||||||
|
int i, c, d;
|
||||||
|
int k, l;
|
||||||
|
char *optchar;
|
||||||
|
|
||||||
|
if (!optind || optreset) {
|
||||||
|
optreset = 0;
|
||||||
|
__optpos = 0;
|
||||||
|
optind = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optind >= argc || !argv[optind])
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (argv[optind][0] != '-') {
|
||||||
|
if (optstring[0] == '-') {
|
||||||
|
optarg = argv[optind++];
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!argv[optind][1])
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (argv[optind][1] == '-' && !argv[optind][2])
|
||||||
|
return optind++, -1;
|
||||||
|
|
||||||
|
if (!optpos) optpos++;
|
||||||
|
c = argv[optind][optpos], k = 1;
|
||||||
|
optchar = argv[optind]+optpos;
|
||||||
|
optopt = c;
|
||||||
|
optpos += k;
|
||||||
|
|
||||||
|
if (!argv[optind][optpos]) {
|
||||||
|
optind++;
|
||||||
|
optpos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (optstring[0] == '-' || optstring[0] == '+')
|
||||||
|
optstring++;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
d = 0;
|
||||||
|
do {
|
||||||
|
d = optstring[i], l = 1;
|
||||||
|
if (l>0) i+=l; else i++;
|
||||||
|
} while (l && d != c);
|
||||||
|
|
||||||
|
if (d != c) {
|
||||||
|
if (optstring[0] != ':' && opterr)
|
||||||
|
__getopt_msg(argv[0], ": unrecognized option: ", optchar, k);
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
if (optstring[i] == ':') {
|
||||||
|
if (optstring[i+1] == ':') optarg = 0;
|
||||||
|
else if (optind >= argc) {
|
||||||
|
if (optstring[0] == ':') return ':';
|
||||||
|
if (opterr) __getopt_msg(argv[0],
|
||||||
|
": option requires an argument: ",
|
||||||
|
optchar, k);
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
if (optstring[i+1] != ':' || optpos) {
|
||||||
|
optarg = argv[optind++] + optpos;
|
||||||
|
optpos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void permute(char *const *argv, int dest, int src)
|
||||||
|
{
|
||||||
|
char **av = (char **)argv;
|
||||||
|
char *tmp = av[src];
|
||||||
|
int i;
|
||||||
|
for (i=src; i>dest; i--)
|
||||||
|
av[i] = av[i-1];
|
||||||
|
av[dest] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
|
{
|
||||||
|
optarg = 0;
|
||||||
|
if (longopts && argv[optind][0] == '-' &&
|
||||||
|
((longonly && argv[optind][1] && argv[optind][1] != '-') ||
|
||||||
|
(argv[optind][1] == '-' && argv[optind][2])))
|
||||||
|
{
|
||||||
|
int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':';
|
||||||
|
int i, cnt, match = -1;
|
||||||
|
char *opt;
|
||||||
|
for (cnt=i=0; longopts[i].name; i++) {
|
||||||
|
const char *name = longopts[i].name;
|
||||||
|
opt = argv[optind]+1;
|
||||||
|
if (*opt == '-') opt++;
|
||||||
|
for (; *name && *name == *opt; name++, opt++);
|
||||||
|
if (*opt && *opt != '=') continue;
|
||||||
|
match = i;
|
||||||
|
if (!*name) {
|
||||||
|
cnt = 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cnt++;
|
||||||
|
}
|
||||||
|
if (cnt==1) {
|
||||||
|
i = match;
|
||||||
|
optind++;
|
||||||
|
optopt = longopts[i].val;
|
||||||
|
if (*opt == '=') {
|
||||||
|
if (!longopts[i].has_arg) {
|
||||||
|
if (colon || !opterr)
|
||||||
|
return '?';
|
||||||
|
__getopt_msg(argv[0],
|
||||||
|
": option does not take an argument: ",
|
||||||
|
longopts[i].name,
|
||||||
|
strlen(longopts[i].name));
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
optarg = opt+1;
|
||||||
|
} else if (longopts[i].has_arg == required_argument) {
|
||||||
|
if (!(optarg = argv[optind])) {
|
||||||
|
if (colon) return ':';
|
||||||
|
if (!opterr) return '?';
|
||||||
|
__getopt_msg(argv[0],
|
||||||
|
": option requires an argument: ",
|
||||||
|
longopts[i].name,
|
||||||
|
strlen(longopts[i].name));
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
optind++;
|
||||||
|
}
|
||||||
|
if (idx) *idx = i;
|
||||||
|
if (longopts[i].flag) {
|
||||||
|
*longopts[i].flag = longopts[i].val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return longopts[i].val;
|
||||||
|
}
|
||||||
|
if (argv[optind][1] == '-') {
|
||||||
|
if (!colon && opterr)
|
||||||
|
__getopt_msg(argv[0], cnt ?
|
||||||
|
": option is ambiguous: " :
|
||||||
|
": unrecognized option: ",
|
||||||
|
argv[optind]+2,
|
||||||
|
strlen(argv[optind]+2));
|
||||||
|
optind++;
|
||||||
|
return '?';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getopt(argc, argv, optstring);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly)
|
||||||
|
{
|
||||||
|
int ret, skipped, resumed;
|
||||||
|
if (!optind || optreset) {
|
||||||
|
optreset = 0;
|
||||||
|
__optpos = 0;
|
||||||
|
optind = 1;
|
||||||
|
}
|
||||||
|
if (optind >= argc || !argv[optind]) return -1;
|
||||||
|
skipped = optind;
|
||||||
|
if (optstring[0] != '+' && optstring[0] != '-') {
|
||||||
|
int i;
|
||||||
|
for (i=optind; ; i++) {
|
||||||
|
if (i >= argc || !argv[i]) return -1;
|
||||||
|
if (argv[i][0] == '-' && argv[i][1]) break;
|
||||||
|
}
|
||||||
|
optind = i;
|
||||||
|
}
|
||||||
|
resumed = optind;
|
||||||
|
ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly);
|
||||||
|
if (resumed > skipped) {
|
||||||
|
int i, cnt = optind-resumed;
|
||||||
|
for (i=0; i<cnt; i++)
|
||||||
|
permute(argv, skipped, optind-1);
|
||||||
|
optind = skipped + cnt;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
|
||||||
|
{
|
||||||
|
return __getopt_long(argc, argv, optstring, longopts, idx, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx)
|
||||||
|
{
|
||||||
|
return __getopt_long(argc, argv, optstring, longopts, idx, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _WIN32
|
53
getopt.h
Normal file
53
getopt.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2005-2014 Rich Felker, et al.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
|
a copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be
|
||||||
|
included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _GETOPT_H
|
||||||
|
#define _GETOPT_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int getopt(int, char * const [], const char *);
|
||||||
|
extern char *optarg;
|
||||||
|
extern int optind, opterr, optopt, optreset;
|
||||||
|
|
||||||
|
struct option {
|
||||||
|
const char *name;
|
||||||
|
int has_arg;
|
||||||
|
int *flag;
|
||||||
|
int val;
|
||||||
|
};
|
||||||
|
|
||||||
|
int getopt_long(int, char *const *, const char *, const struct option *, int *);
|
||||||
|
int getopt_long_only(int, char *const *, const char *, const struct option *, int *);
|
||||||
|
|
||||||
|
#define no_argument 0
|
||||||
|
#define required_argument 1
|
||||||
|
#define optional_argument 2
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
15
isatty.c
Normal file
15
isatty.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "isatty.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
int isatty(int fd) {
|
||||||
|
// TODO: Make it work for win32
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fileno(FILE *fp) {
|
||||||
|
// TODO: Make it work for win32
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _WIN32
|
6
isatty.h
Normal file
6
isatty.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int isatty(int fd);
|
||||||
|
int fileno(FILE *fp);
|
10
makefile
10
makefile
@ -14,11 +14,13 @@ LDFLAGS_32=$(LDFLAGS) -m32
|
|||||||
all: umka_shell umka_fuse umka_os umka_gen_devices_dat umka.sym umka.prp \
|
all: umka_shell umka_fuse umka_os umka_gen_devices_dat umka.sym umka.prp \
|
||||||
umka.lst tags covpreproc default.skn skin.skn
|
umka.lst tags covpreproc default.skn skin.skn
|
||||||
|
|
||||||
|
.PHONY: test
|
||||||
|
|
||||||
covpreproc: covpreproc.c
|
covpreproc: covpreproc.c
|
||||||
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
|
$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@
|
||||||
|
|
||||||
umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o vnet.o \
|
umka_shell: umka_shell.o umka.o shell.o trace.o trace_lbr.o vdisk.o vnet.o \
|
||||||
lodepng.o pci.o thread.o util.o
|
lodepng.o pci.o thread.o util.o getopt.o isatty.o
|
||||||
$(CC) $(LDFLAGS_32) $^ -o $@ -static -T umka.ld
|
$(CC) $(LDFLAGS_32) $^ -o $@ -static -T umka.ld
|
||||||
|
|
||||||
umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o pci.o thread.o
|
umka_fuse: umka_fuse.o umka.o trace.o trace_lbr.o vdisk.o pci.o thread.o
|
||||||
@ -47,6 +49,12 @@ pci.o: linux/pci.c
|
|||||||
lodepng.o: lodepng.c lodepng.h
|
lodepng.o: lodepng.c lodepng.h
|
||||||
$(CC) $(CFLAGS_32) -c $<
|
$(CC) $(CFLAGS_32) -c $<
|
||||||
|
|
||||||
|
getopt.o: getopt.c getopt.h
|
||||||
|
$(CC) $(CFLAGS_32) -c $<
|
||||||
|
|
||||||
|
isatty.o: isatty.c isatty.h
|
||||||
|
$(CC) $(CFLAGS_32) -c $<
|
||||||
|
|
||||||
util.o: util.c util.h umka.h
|
util.o: util.c util.h umka.h
|
||||||
$(CC) $(CFLAGS_32) -c $<
|
$(CC) $(CFLAGS_32) -c $<
|
||||||
|
|
||||||
|
46
shell.c
46
shell.c
@ -25,19 +25,18 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <fcntl.h>
|
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <netinet/in.h>
|
|
||||||
#include <arpa/inet.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
// TODO: Cleanup
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "isatty.h"
|
||||||
|
#include "getopt.h"
|
||||||
#include "vdisk.h"
|
#include "vdisk.h"
|
||||||
#include "vnet.h"
|
#include "vnet.h"
|
||||||
#include "umka.h"
|
#include "umka.h"
|
||||||
@ -211,6 +210,10 @@ next_line(int is_tty, int block) {
|
|||||||
if (is_tty) {
|
if (is_tty) {
|
||||||
prompt();
|
prompt();
|
||||||
}
|
}
|
||||||
|
// TODO: Cleanup
|
||||||
|
#ifdef _WIN32
|
||||||
|
return fgets(cmd_buf, FGETS_BUF_LEN, fin) != NULL;
|
||||||
|
#else
|
||||||
if (block) {
|
if (block) {
|
||||||
return fgets(cmd_buf, FGETS_BUF_LEN, fin) != NULL;
|
return fgets(cmd_buf, FGETS_BUF_LEN, fin) != NULL;
|
||||||
} else {
|
} else {
|
||||||
@ -230,6 +233,7 @@ next_line(int is_tty, int block) {
|
|||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -338,7 +342,7 @@ shell_ramdisk_init(int argc, char **argv) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char *fname = argv[1];
|
const char *fname = argv[1];
|
||||||
FILE *f = fopen(fname, "r");
|
FILE *f = fopen(fname, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(fout, "[!] can't open file '%s': %s\n", fname, strerror(errno));
|
fprintf(fout, "[!] can't open file '%s': %s\n", fname, strerror(errno));
|
||||||
return;
|
return;
|
||||||
@ -1124,7 +1128,7 @@ shell_put_image(int argc, char **argv) {
|
|||||||
fputs(usage, fout);
|
fputs(usage, fout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FILE *f = fopen(argv[1], "r");
|
FILE *f = fopen(argv[1], "rb");
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size_t fsize = ftell(f);
|
size_t fsize = ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
@ -1157,7 +1161,7 @@ shell_put_image_palette(int argc, char **argv) {
|
|||||||
fputs(usage, fout);
|
fputs(usage, fout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FILE *f = fopen(argv[1], "r");
|
FILE *f = fopen(argv[1], "rb");
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size_t fsize = ftell(f);
|
size_t fsize = ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
@ -1363,7 +1367,7 @@ shell_blit_bitmap(int argc, char **argv) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const char *fname = argv[1];
|
const char *fname = argv[1];
|
||||||
FILE *f = fopen(fname, "r");
|
FILE *f = fopen(fname, "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(fout, "[!] can't open file '%s': %s\n", fname, strerror(errno));
|
fprintf(fout, "[!] can't open file '%s': %s\n", fname, strerror(errno));
|
||||||
return;
|
return;
|
||||||
@ -1808,7 +1812,7 @@ shell_acpi_preload_table(int argc, char **argv) {
|
|||||||
fputs(usage, fout);
|
fputs(usage, fout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FILE *f = fopen(argv[1], "r");
|
FILE *f = fopen(argv[1], "rb");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
fprintf(fout, "[umka] can't open file: %s\n", argv[1]);
|
fprintf(fout, "[umka] can't open file: %s\n", argv[1]);
|
||||||
return;
|
return;
|
||||||
@ -1947,6 +1951,8 @@ shell_pci_get_path(int argc, char **argv) {
|
|||||||
fprintf(fout, "pci path: %s\n", pci_path);
|
fprintf(fout, "pci path: %s\n", pci_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shell_stack_init(int argc, char **argv) {
|
shell_stack_init(int argc, char **argv) {
|
||||||
const char *usage = \
|
const char *usage = \
|
||||||
@ -2602,6 +2608,8 @@ shell_net_arp_del_entry(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shell_bg_set_size(int argc, char **argv) {
|
shell_bg_set_size(int argc, char **argv) {
|
||||||
const char *usage = \
|
const char *usage = \
|
||||||
@ -2667,7 +2675,7 @@ shell_bg_put_img(int argc, char **argv) {
|
|||||||
fputs(usage, fout);
|
fputs(usage, fout);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FILE *f = fopen(argv[1], "r");
|
FILE *f = fopen(argv[1], "rb");
|
||||||
fseek(f, 0, SEEK_END);
|
fseek(f, 0, SEEK_END);
|
||||||
size_t fsize = ftell(f);
|
size_t fsize = ftell(f);
|
||||||
rewind(f);
|
rewind(f);
|
||||||
@ -2754,6 +2762,8 @@ func_table_t shell_cmds[] = {
|
|||||||
{ "ls80", shell_ls80 },
|
{ "ls80", shell_ls80 },
|
||||||
{ "move_window", shell_move_window },
|
{ "move_window", shell_move_window },
|
||||||
{ "mouse_move", shell_mouse_move },
|
{ "mouse_move", shell_mouse_move },
|
||||||
|
#ifndef _WIN32
|
||||||
|
{ "stack_init", shell_stack_init },
|
||||||
{ "net_accept", shell_net_accept },
|
{ "net_accept", shell_net_accept },
|
||||||
{ "net_add_device", shell_net_add_device },
|
{ "net_add_device", shell_net_add_device },
|
||||||
{ "net_arp_add_entry", shell_net_arp_add_entry },
|
{ "net_arp_add_entry", shell_net_arp_add_entry },
|
||||||
@ -2785,6 +2795,7 @@ func_table_t shell_cmds[] = {
|
|||||||
{ "net_ipv4_set_subnet", shell_net_ipv4_set_subnet },
|
{ "net_ipv4_set_subnet", shell_net_ipv4_set_subnet },
|
||||||
{ "net_listen", shell_net_listen },
|
{ "net_listen", shell_net_listen },
|
||||||
{ "net_open_socket", shell_net_open_socket },
|
{ "net_open_socket", shell_net_open_socket },
|
||||||
|
#endif // _WIN32
|
||||||
{ "pci_get_path", shell_pci_get_path },
|
{ "pci_get_path", shell_pci_get_path },
|
||||||
{ "pci_set_path", shell_pci_set_path },
|
{ "pci_set_path", shell_pci_set_path },
|
||||||
{ "process_info", shell_process_info },
|
{ "process_info", shell_process_info },
|
||||||
@ -2805,7 +2816,6 @@ func_table_t shell_cmds[] = {
|
|||||||
{ "set_skin", shell_set_skin },
|
{ "set_skin", shell_set_skin },
|
||||||
{ "set_window_caption", shell_set_window_caption },
|
{ "set_window_caption", shell_set_window_caption },
|
||||||
{ "set_window_colors", shell_set_window_colors },
|
{ "set_window_colors", shell_set_window_colors },
|
||||||
{ "stack_init", shell_stack_init },
|
|
||||||
{ "stat70", shell_stat70 },
|
{ "stat70", shell_stat70 },
|
||||||
{ "stat80", shell_stat80 },
|
{ "stat80", shell_stat80 },
|
||||||
{ "window_redraw", shell_window_redraw },
|
{ "window_redraw", shell_window_redraw },
|
||||||
@ -2852,7 +2862,7 @@ run_test(FILE *in, FILE *out, int block) {
|
|||||||
fin = in;
|
fin = in;
|
||||||
fout = out;
|
fout = out;
|
||||||
int is_tty = isatty(fileno(fin));
|
int is_tty = isatty(fileno(fin));
|
||||||
char **argv = (char**)malloc(sizeof(char*) * (MAX_COMMAND_ARGS + 1));
|
char **argv = (char**)calloc(sizeof(char*), (MAX_COMMAND_ARGS + 1));
|
||||||
while(next_line(is_tty, block)) {
|
while(next_line(is_tty, block)) {
|
||||||
if (cmd_buf[0] == '#' || cmd_buf[0] == '\n' || cmd_buf[0] == '\0' ||
|
if (cmd_buf[0] == '#' || cmd_buf[0] == '\n' || cmd_buf[0] == '\0' ||
|
||||||
cmd_buf[0] == '\r') {
|
cmd_buf[0] == '\r') {
|
||||||
|
32
trace_lbr.c
32
trace_lbr.c
@ -1,11 +1,12 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
#ifndef _WIN32
|
||||||
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <signal.h>
|
#endif
|
||||||
|
|
||||||
#include "umka.h"
|
#include "umka.h"
|
||||||
|
|
||||||
#define MSR_IA32_DEBUGCTLMSR 0x1d9
|
#define MSR_IA32_DEBUGCTLMSR 0x1d9
|
||||||
@ -16,18 +17,23 @@ int covfd, msrfd;
|
|||||||
|
|
||||||
uint64_t rdmsr(uint32_t reg)
|
uint64_t rdmsr(uint32_t reg)
|
||||||
{
|
{
|
||||||
uint64_t data;
|
uint64_t data = 0;
|
||||||
|
|
||||||
|
#ifndef _WIN32
|
||||||
if (pread(msrfd, &data, sizeof data, reg) != sizeof data) {
|
if (pread(msrfd, &data, sizeof data, reg) != sizeof data) {
|
||||||
perror("rdmsr: pread");
|
perror("rdmsr: pread");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wrmsr(uint32_t reg, uint64_t data)
|
void wrmsr(uint32_t reg, uint64_t data)
|
||||||
{
|
{
|
||||||
|
#ifndef _WIN32
|
||||||
int fd;
|
int fd;
|
||||||
fd = open("/dev/cpu/0/msr", O_WRONLY);
|
fd = open("/dev/cpu/0/msr", O_WRONLY);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
@ -41,10 +47,13 @@ void wrmsr(uint32_t reg, uint64_t data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close(fd);
|
||||||
return;
|
#else
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_sigtrap() {
|
void handle_sigtrap() {
|
||||||
|
#ifndef _WIN32
|
||||||
uint64_t from = rdmsr(MSR_IA32_LASTBRANCHFROMIP);
|
uint64_t from = rdmsr(MSR_IA32_LASTBRANCHFROMIP);
|
||||||
uint64_t to = rdmsr(MSR_IA32_LASTBRANCHTOIP);
|
uint64_t to = rdmsr(MSR_IA32_LASTBRANCHTOIP);
|
||||||
|
|
||||||
@ -55,11 +64,15 @@ void handle_sigtrap() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wrmsr(MSR_IA32_DEBUGCTLMSR, 3);
|
wrmsr(MSR_IA32_DEBUGCTLMSR, 3);
|
||||||
|
#else
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t set_eflags_tf(uint32_t tf);
|
uint32_t set_eflags_tf(uint32_t tf);
|
||||||
|
|
||||||
void trace_lbr_begin() {
|
void trace_lbr_begin() {
|
||||||
|
#ifndef _WIN32
|
||||||
struct sigaction action;
|
struct sigaction action;
|
||||||
action.sa_sigaction = &handle_sigtrap;
|
action.sa_sigaction = &handle_sigtrap;
|
||||||
action.sa_flags = SA_SIGINFO;
|
action.sa_flags = SA_SIGINFO;
|
||||||
@ -78,12 +91,19 @@ void trace_lbr_begin() {
|
|||||||
void *coverage_end_addr = coverage_end;
|
void *coverage_end_addr = coverage_end;
|
||||||
write(covfd, &coverage_begin_addr, 4);
|
write(covfd, &coverage_begin_addr, 4);
|
||||||
write(covfd, &coverage_end_addr, 4);
|
write(covfd, &coverage_end_addr, 4);
|
||||||
|
#else
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void trace_lbr_end() {
|
void trace_lbr_end() {
|
||||||
|
#ifndef _WIN32
|
||||||
wrmsr(MSR_IA32_DEBUGCTLMSR, 0);
|
wrmsr(MSR_IA32_DEBUGCTLMSR, 0);
|
||||||
close(msrfd);
|
close(msrfd);
|
||||||
close(covfd);
|
close(covfd);
|
||||||
|
#else
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t trace_lbr_pause(void) {
|
uint32_t trace_lbr_pause(void) {
|
||||||
|
249
umka.asm
249
umka.asm
@ -1,6 +1,68 @@
|
|||||||
; TODO: SPDX
|
; TODO: SPDX
|
||||||
|
|
||||||
format ELF
|
if defined WIN32
|
||||||
|
format MS COFF
|
||||||
|
else
|
||||||
|
format ELF
|
||||||
|
end if
|
||||||
|
|
||||||
|
; win32:
|
||||||
|
; pubsym name -> public name as "_name"
|
||||||
|
; pubsym name, 20 -> public name as "_name@20"
|
||||||
|
; pubsym name, no_mangle -> public name
|
||||||
|
; pubsym name, "name" -> public name as "_name"
|
||||||
|
; pubsym name, "name", 20 -> public name as "_name@20"
|
||||||
|
; pubsym name, "name", no_mangle -> public name as "name"
|
||||||
|
; linux:
|
||||||
|
; pubsym name -> public name
|
||||||
|
; pubsym name, 20 -> public name
|
||||||
|
; pubsym name, no_mangle -> public name
|
||||||
|
; pubsym name, "name" -> public name as "name"
|
||||||
|
; pubsym name, "name", 20 -> public name as "name"
|
||||||
|
; pubsym name, "name", no_mangle -> public name as "name"
|
||||||
|
macro pubsym name, marg1, marg2 {
|
||||||
|
if defined WIN32
|
||||||
|
if marg1 eq no_mangle
|
||||||
|
public name
|
||||||
|
else if marg1 eqtype 20
|
||||||
|
public name as '_' # `name # '@' # `marg1
|
||||||
|
else if marg1 eqtype 'string'
|
||||||
|
if marg2 eq no_mangle
|
||||||
|
public name as marg1
|
||||||
|
else if marg2 eqtype 20
|
||||||
|
public name as '_' # marg1 # '@' # `marg2
|
||||||
|
else
|
||||||
|
public name as '_' # marg1
|
||||||
|
end if
|
||||||
|
else
|
||||||
|
public name as '_' # `name
|
||||||
|
end if
|
||||||
|
else
|
||||||
|
if marg1 eqtype 'string'
|
||||||
|
public name as marg1
|
||||||
|
else
|
||||||
|
public name
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
}
|
||||||
|
|
||||||
|
; win32:
|
||||||
|
; extrn name -> extrn _name
|
||||||
|
; extrn name, 20 -> extrn _name@20
|
||||||
|
; linux:
|
||||||
|
; extrn name -> extrn name
|
||||||
|
; extrn name, 20 -> extrn name
|
||||||
|
macro extrn name, [argsize] {
|
||||||
|
if defined WIN32
|
||||||
|
if argsize eqtype 20
|
||||||
|
extrn '_' # `name # '@' # `argsize as name
|
||||||
|
else
|
||||||
|
extrn '_' # `name as name
|
||||||
|
end if
|
||||||
|
else
|
||||||
|
extrn name
|
||||||
|
end if
|
||||||
|
}
|
||||||
|
|
||||||
__DEBUG__ = 1
|
__DEBUG__ = 1
|
||||||
__DEBUG_LEVEL__ = 1
|
__DEBUG_LEVEL__ = 1
|
||||||
@ -11,92 +73,92 @@ UMKA_OS = 3
|
|||||||
|
|
||||||
UMKA_MEMORY_BYTES = 256 SHL 20
|
UMKA_MEMORY_BYTES = 256 SHL 20
|
||||||
|
|
||||||
public disk_add
|
pubsym disk_add, 16
|
||||||
public disk_del
|
pubsym disk_del, 4
|
||||||
public disk_list
|
pubsym disk_list
|
||||||
public disk_media_changed
|
pubsym disk_media_changed, 8
|
||||||
|
|
||||||
public xfs._.user_functions as 'xfs_user_functions'
|
pubsym xfs._.user_functions, 'xfs_user_functions'
|
||||||
public ext_user_functions
|
pubsym ext_user_functions
|
||||||
public fat_user_functions
|
pubsym fat_user_functions
|
||||||
public ntfs_user_functions
|
pubsym ntfs_user_functions
|
||||||
|
|
||||||
public i40
|
pubsym i40, no_mangle
|
||||||
|
|
||||||
public coverage_begin
|
pubsym coverage_begin
|
||||||
public coverage_end
|
pubsym coverage_end
|
||||||
|
|
||||||
public sha3_256_oneshot as 'hash_oneshot'
|
pubsym sha3_256_oneshot, 'hash_oneshot'
|
||||||
public kos_time_to_epoch
|
pubsym kos_time_to_epoch
|
||||||
public umka_init
|
pubsym umka_init
|
||||||
|
|
||||||
public current_process as 'kos_current_process'
|
pubsym current_process, 'kos_current_process'
|
||||||
public current_slot as 'kos_current_slot'
|
pubsym current_slot, 'kos_current_slot'
|
||||||
public current_slot_idx as 'kos_current_slot_idx'
|
pubsym current_slot_idx, 'kos_current_slot_idx'
|
||||||
|
|
||||||
public thread_count as 'kos_thread_count'
|
pubsym thread_count, 'kos_thread_count'
|
||||||
public TASK_TABLE as 'kos_task_table'
|
pubsym TASK_TABLE, 'kos_task_table'
|
||||||
public TASK_BASE as 'kos_task_base'
|
pubsym TASK_BASE, 'kos_task_base'
|
||||||
public TASK_DATA as 'kos_task_data'
|
pubsym TASK_DATA, 'kos_task_data'
|
||||||
public SLOT_BASE as 'kos_slot_base'
|
pubsym SLOT_BASE, 'kos_slot_base'
|
||||||
public window_data as 'kos_window_data'
|
pubsym window_data, 'kos_window_data'
|
||||||
|
|
||||||
public WIN_STACK as 'kos_win_stack'
|
pubsym WIN_STACK, 'kos_win_stack'
|
||||||
public WIN_POS as 'kos_win_pos'
|
pubsym WIN_POS, 'kos_win_pos'
|
||||||
public lfb_base as 'kos_lfb_base'
|
pubsym lfb_base, 'kos_lfb_base'
|
||||||
|
|
||||||
public RAMDISK as 'kos_ramdisk'
|
pubsym RAMDISK, 'kos_ramdisk'
|
||||||
public ramdisk_init as 'kos_ramdisk_init'
|
pubsym ramdisk_init, 'kos_ramdisk_init'
|
||||||
|
|
||||||
public enable_acpi
|
pubsym enable_acpi, no_mangle
|
||||||
public acpi.call_name
|
pubsym acpi.call_name, no_mangle
|
||||||
public acpi_ssdt_cnt as 'kos_acpi_ssdt_cnt'
|
pubsym acpi_ssdt_cnt, 'kos_acpi_ssdt_cnt'
|
||||||
public acpi_ssdt_base as 'kos_acpi_ssdt_base'
|
pubsym acpi_ssdt_base, 'kos_acpi_ssdt_base'
|
||||||
public acpi_ssdt_size as 'kos_acpi_ssdt_size'
|
pubsym acpi_ssdt_size, 'kos_acpi_ssdt_size'
|
||||||
public acpi_ctx
|
pubsym acpi_ctx
|
||||||
public acpi_usage as 'kos_acpi_usage'
|
pubsym acpi_usage, 'kos_acpi_usage'
|
||||||
public acpi_node_alloc_cnt as 'kos_acpi_node_alloc_cnt'
|
pubsym acpi_node_alloc_cnt, 'kos_acpi_node_alloc_cnt'
|
||||||
public acpi_node_free_cnt as 'kos_acpi_node_free_cnt'
|
pubsym acpi_node_free_cnt, 'kos_acpi_node_free_cnt'
|
||||||
public acpi.count_nodes as 'kos_acpi_count_nodes'
|
pubsym acpi.count_nodes, 'kos_acpi_count_nodes', 4
|
||||||
|
|
||||||
public stack_init as 'kos_stack_init'
|
pubsym stack_init, 'kos_stack_init'
|
||||||
public net_add_device
|
pubsym net_add_device
|
||||||
|
|
||||||
public draw_data
|
pubsym draw_data
|
||||||
public img_background
|
pubsym img_background
|
||||||
public mem_BACKGROUND
|
pubsym mem_BACKGROUND
|
||||||
public sys_background
|
pubsym sys_background
|
||||||
public REDRAW_BACKGROUND as 'kos_redraw_background'
|
pubsym REDRAW_BACKGROUND, 'kos_redraw_background'
|
||||||
public new_sys_threads as 'kos_new_sys_threads'
|
pubsym new_sys_threads, 'kos_new_sys_threads', no_mangle
|
||||||
public osloop as 'kos_osloop'
|
pubsym osloop, 'kos_osloop'
|
||||||
public set_mouse_data as 'kos_set_mouse_data'
|
pubsym set_mouse_data, 'kos_set_mouse_data', 20
|
||||||
public scheduler_current as 'kos_scheduler_current'
|
pubsym scheduler_current, 'kos_scheduler_current'
|
||||||
public kos_eth_input
|
pubsym kos_eth_input
|
||||||
public net_buff_alloc as 'kos_net_buff_alloc'
|
pubsym net_buff_alloc, 'kos_net_buff_alloc', 4
|
||||||
|
|
||||||
public mem_block_list
|
pubsym mem_block_list
|
||||||
public pci_root as "kos_pci_root"
|
pubsym pci_root, "kos_pci_root"
|
||||||
|
|
||||||
public acpi.aml.init as "kos_acpi_aml_init"
|
pubsym acpi.aml.init, "kos_acpi_aml_init"
|
||||||
public acpi_root as "kos_acpi_root"
|
pubsym acpi_root, "kos_acpi_root"
|
||||||
public aml._.attach as "kos_aml_attach"
|
pubsym aml._.attach, "kos_aml_attach"
|
||||||
public acpi.fill_pci_irqs as "kos_acpi_fill_pci_irqs"
|
pubsym acpi.fill_pci_irqs, "kos_acpi_fill_pci_irqs"
|
||||||
public pci.walk_tree as "kos_pci_walk_tree"
|
pubsym pci.walk_tree, "kos_pci_walk_tree", 16
|
||||||
public acpi.aml.new_thread as "kos_acpi_aml_new_thread"
|
pubsym acpi.aml.new_thread, "kos_acpi_aml_new_thread"
|
||||||
public aml._.alloc_node as "kos_aml_alloc_node"
|
pubsym aml._.alloc_node, "kos_aml_alloc_node"
|
||||||
public aml._.constructor.integer as "kos_aml_constructor_integer"
|
pubsym aml._.constructor.integer, "kos_aml_constructor_integer"
|
||||||
public aml._.constructor.package as "kos_aml_constructor_package"
|
pubsym aml._.constructor.package, "kos_aml_constructor_package"
|
||||||
public acpi._.lookup_node as "kos_acpi_lookup_node"
|
pubsym acpi._.lookup_node, "kos_acpi_lookup_node"
|
||||||
public acpi._.print_tree as "kos_acpi_print_tree"
|
pubsym acpi._.print_tree, "kos_acpi_print_tree"
|
||||||
public acpi_dev_data as "kos_acpi_dev_data"
|
pubsym acpi_dev_data, "kos_acpi_dev_data"
|
||||||
public acpi_dev_size as "kos_acpi_dev_size"
|
pubsym acpi_dev_size, "kos_acpi_dev_size"
|
||||||
public acpi_dev_next as "kos_acpi_dev_next"
|
pubsym acpi_dev_next, "kos_acpi_dev_next"
|
||||||
public kernel_alloc as "kos_kernel_alloc"
|
pubsym kernel_alloc, "kos_kernel_alloc"
|
||||||
|
|
||||||
public window._.set_screen as 'kos_window_set_screen'
|
pubsym window._.set_screen, 'kos_window_set_screen'
|
||||||
public _display as 'kos_display'
|
pubsym _display, 'kos_display'
|
||||||
|
|
||||||
public BOOT as 'kos_boot'
|
pubsym BOOT, 'kos_boot'
|
||||||
|
|
||||||
macro cli {
|
macro cli {
|
||||||
pushfd
|
pushfd
|
||||||
@ -130,8 +192,12 @@ include 'macros.inc'
|
|||||||
|
|
||||||
macro diff16 msg,blah2,blah3 {
|
macro diff16 msg,blah2,blah3 {
|
||||||
if msg eq "end of .data segment"
|
if msg eq "end of .data segment"
|
||||||
; fasm doesn't align on 65536, but ld script does
|
if defined WIN32
|
||||||
section '.bss.aligned65k' writeable align 65536
|
section '.bss.8k' writeable align 8192
|
||||||
|
else
|
||||||
|
; fasm doesn't align on 65536, but ld script does
|
||||||
|
section '.bss.aligned65k' writeable align 65536
|
||||||
|
end if
|
||||||
bss_base:
|
bss_base:
|
||||||
end if
|
end if
|
||||||
}
|
}
|
||||||
@ -328,7 +394,7 @@ proc umka._.check_alignment
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
public i40_asm
|
pubsym i40_asm
|
||||||
|
|
||||||
;void i40_asm(uint32_t _eax,
|
;void i40_asm(uint32_t _eax,
|
||||||
; uint32_t _ebx,
|
; uint32_t _ebx,
|
||||||
@ -359,7 +425,7 @@ i40_asm:
|
|||||||
pop ebp edi esi edx ecx ebx eax
|
pop ebp edi esi edx ecx ebx eax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
public set_eflags_tf
|
pubsym set_eflags_tf
|
||||||
|
|
||||||
proc set_eflags_tf c uses ebx esi edi ebp, tf
|
proc set_eflags_tf c uses ebx esi edi ebp, tf
|
||||||
mov ecx, [tf]
|
mov ecx, [tf]
|
||||||
@ -581,7 +647,7 @@ proc umka_init c uses ebx esi edi ebp
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
public skin_udata
|
pubsym skin_udata
|
||||||
proc idle uses ebx esi edi
|
proc idle uses ebx esi edi
|
||||||
.loop:
|
.loop:
|
||||||
mov ecx, 10000000
|
mov ecx, 10000000
|
||||||
@ -593,7 +659,7 @@ proc idle uses ebx esi edi
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
extrn pci_read
|
extrn pci_read, 20
|
||||||
proc pci_read_reg uses ebx esi edi
|
proc pci_read_reg uses ebx esi edi
|
||||||
mov ecx, eax
|
mov ecx, eax
|
||||||
and ecx, 3
|
and ecx, 3
|
||||||
@ -617,6 +683,14 @@ endp
|
|||||||
proc sys_msg_board
|
proc sys_msg_board
|
||||||
cmp cl, 0x0d
|
cmp cl, 0x0d
|
||||||
jz @f
|
jz @f
|
||||||
|
if defined WIN32
|
||||||
|
extrn putchar
|
||||||
|
pushad
|
||||||
|
push ecx
|
||||||
|
call putchar
|
||||||
|
pop ecx
|
||||||
|
popad
|
||||||
|
else
|
||||||
pushad
|
pushad
|
||||||
mov eax, SYS_WRITE
|
mov eax, SYS_WRITE
|
||||||
mov ebx, STDOUT
|
mov ebx, STDOUT
|
||||||
@ -626,6 +700,7 @@ proc sys_msg_board
|
|||||||
int 0x80
|
int 0x80
|
||||||
pop ecx
|
pop ecx
|
||||||
popad
|
popad
|
||||||
|
end if
|
||||||
@@:
|
@@:
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
@ -635,13 +710,13 @@ proc delay_ms
|
|||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
public umka_cli
|
pubsym umka_cli
|
||||||
proc umka_cli
|
proc umka_cli
|
||||||
cli ; macro
|
cli ; macro
|
||||||
ret
|
ret
|
||||||
endp
|
endp
|
||||||
|
|
||||||
public umka_sti
|
pubsym umka_sti
|
||||||
proc umka_sti
|
proc umka_sti
|
||||||
sti ; macro
|
sti ; macro
|
||||||
ret
|
ret
|
||||||
@ -649,7 +724,7 @@ endp
|
|||||||
|
|
||||||
extrn reset_procmask
|
extrn reset_procmask
|
||||||
extrn get_fake_if
|
extrn get_fake_if
|
||||||
public irq0
|
pubsym irq0
|
||||||
proc irq0 c, _signo, _info, _context
|
proc irq0 c, _signo, _info, _context
|
||||||
DEBUGF 2, "### irq0\n"
|
DEBUGF 2, "### irq0\n"
|
||||||
pushfd
|
pushfd
|
||||||
@ -813,11 +888,15 @@ restore sys_msg_board,delay_ms
|
|||||||
|
|
||||||
coverage_end:
|
coverage_end:
|
||||||
|
|
||||||
; fasm doesn't align on 65536, but ld script does
|
if defined WIN32
|
||||||
section '.data.aligned65k' writeable align 65536
|
section '.data.8k' writeable align 8192
|
||||||
public umka_tool
|
else
|
||||||
|
; fasm doesn't align on 65536, but ld script does
|
||||||
|
section '.data.aligned65k' writeable align 65536
|
||||||
|
end if
|
||||||
|
pubsym umka_tool
|
||||||
umka_tool dd ?
|
umka_tool dd ?
|
||||||
public umka_initialized
|
pubsym umka_initialized
|
||||||
umka_initialized dd 0
|
umka_initialized dd 0
|
||||||
fpu_owner dd ?
|
fpu_owner dd ?
|
||||||
|
|
||||||
|
10
umka.h
10
umka.h
@ -3,7 +3,15 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
// TODO: Cleanup
|
||||||
|
#ifndef _WIN32
|
||||||
#include <signal.h> // for irq0: siginfo_t
|
#include <signal.h> // for irq0: siginfo_t
|
||||||
|
#else
|
||||||
|
typedef int32_t ssize_t;
|
||||||
|
typedef int64_t off_t;
|
||||||
|
#define PATH_MAX 255
|
||||||
|
#endif
|
||||||
|
|
||||||
#define STDCALL __attribute__((__stdcall__))
|
#define STDCALL __attribute__((__stdcall__))
|
||||||
|
|
||||||
@ -397,7 +405,7 @@ __attribute__((__noreturn__)) void
|
|||||||
kos_osloop(void);
|
kos_osloop(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
irq0(int signo, siginfo_t *info, void *context);
|
irq0(int signo, void *info, void *context);
|
||||||
|
|
||||||
void
|
void
|
||||||
umka_init(void);
|
umka_init(void);
|
||||||
|
@ -16,15 +16,11 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <fcntl.h>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "umka.h"
|
#include "umka.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
|
7
vdisk.c
7
vdisk.c
@ -7,6 +7,11 @@
|
|||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "vdisk.h"
|
#include "vdisk.h"
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define fseeko _fseeki64
|
||||||
|
#define ftello _ftelli64
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
FILE *file;
|
FILE *file;
|
||||||
uint32_t sect_size;
|
uint32_t sect_size;
|
||||||
@ -16,7 +21,7 @@ typedef struct {
|
|||||||
} vdisk_t;
|
} vdisk_t;
|
||||||
|
|
||||||
void *vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size) {
|
void *vdisk_init(const char *fname, int adjust_cache_size, size_t cache_size) {
|
||||||
FILE *f = fopen(fname, "r+");
|
FILE *f = fopen(fname, "rb+");
|
||||||
if (!f) {
|
if (!f) {
|
||||||
printf("vdisk: can't open file '%s': %s\n", fname, strerror(errno));
|
printf("vdisk: can't open file '%s': %s\n", fname, strerror(errno));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
12
vnet.c
12
vnet.c
@ -1,13 +1,18 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
#include "umka.h"
|
#include "umka.h"
|
||||||
#include "trace.h"
|
#include "trace.h"
|
||||||
#include "vnet.h"
|
#include "vnet.h"
|
||||||
|
|
||||||
|
// TODO: Cleanup
|
||||||
|
#ifndef _WIN32
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int fd;
|
int fd;
|
||||||
} vnet_userdata_t;
|
} vnet_userdata_t;
|
||||||
@ -65,6 +70,10 @@ static void dump_net_buff(net_buff_t *buf) {
|
|||||||
|
|
||||||
STDCALL int
|
STDCALL int
|
||||||
vnet_transmit(net_buff_t *buf) {
|
vnet_transmit(net_buff_t *buf) {
|
||||||
|
// TODO: Separate implementations for win32 and linux
|
||||||
|
#ifdef _WIN32
|
||||||
|
assert(!"Function is not implemented for win32");
|
||||||
|
#else
|
||||||
net_device_t *vnet;
|
net_device_t *vnet;
|
||||||
__asm__ __inline__ __volatile__ (
|
__asm__ __inline__ __volatile__ (
|
||||||
"nop"
|
"nop"
|
||||||
@ -80,6 +89,7 @@ vnet_transmit(net_buff_t *buf) {
|
|||||||
COVERAGE_OFF();
|
COVERAGE_OFF();
|
||||||
COVERAGE_ON();
|
COVERAGE_ON();
|
||||||
printf("vnet_transmit: done\n");
|
printf("vnet_transmit: done\n");
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
win32/pci.c
Executable file
12
win32/pci.c
Executable file
@ -0,0 +1,12 @@
|
|||||||
|
#include "pci.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
char pci_path[PATH_MAX] = ".";
|
||||||
|
|
||||||
|
__attribute__((stdcall)) uint32_t pci_read(uint32_t bus, uint32_t dev,
|
||||||
|
uint32_t fun, uint32_t offset,
|
||||||
|
size_t len) {
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
return 0xffffffff;
|
||||||
|
}
|
8
win32/pci.h
Executable file
8
win32/pci.h
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef PCI_H_INCLUDED
|
||||||
|
#define PCI_H_INCLUDED
|
||||||
|
|
||||||
|
#define PATH_MAX 255
|
||||||
|
|
||||||
|
extern char pci_path[PATH_MAX];
|
||||||
|
|
||||||
|
#endif // PCI_H_INCLUDED
|
8
win32/thread.c
Executable file
8
win32/thread.c
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
void reset_procmask(void) {
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
}
|
||||||
|
|
||||||
|
int get_fake_if(void *ctx) {
|
||||||
|
printf("STUB: %s:%d", __FILE__, __LINE__);
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user