Clean up vnet, update README

This commit is contained in:
Ivan Baravy 2022-06-28 12:23:14 +04:00
parent 7f88bbf11c
commit 155df83d73
4 changed files with 72 additions and 50 deletions

68
README
View File

@ -4,25 +4,35 @@ UMKa -- User-Mode KolibriOS developer tools
This is a common project for a set of KolibriOS developer tools which are based
on original KolibriOS kernel code wrapped and hacked as to run in the UNIX
programming environment. The idea is to make userspace UNIX tools that use as
much unchanged KolibriOS kernel source as possible to test
much unchanged KolibriOS kernel source as possible to run, test and debug
architecture-independent parts of the kernel in your favorite developer
environment.
What works now:
* block layer (disk, cache, partition, MBR, GPT),
* file systems except iso9660 (fat*, exfat, ext*, xfs),
* UI and graphics (geometric primitives, windows, winmap, cursors),
* basic network (configuration, ping replies),
* interrupts (via signals),
* threads and processes,
* scheduler,
* slab allocator,
* events,
* synchronization primitives,
* unpacker,
* string functions,
* other minor functions.
umka_shell
----------
is an interactive shell with commands that are wrappers around KolibriOS kernel
syscalls and other internal functions. What works now: block layer including
disk cache, FS, UI and graphics, scheduler, ACPI/AML interpreter,
synchronization primitives, strings, slab allocator, events, unpacker, other
minor functions.
It can also be used for automated testing by feeding it a file of commands
instead of typing them.
syscalls and other internal functions. It can also be used for automated testing
by feeding it a file of commands instead of typing them.
Example:
$ umka_shell < mytest.t > mytest.out.log
$ umka_shell < mytest.t
umka_fuse
@ -43,20 +53,26 @@ including network stack.
tools
-----
mkdirrange
mkdirrange - make directories with names in range
mkfilepattern
mkfilepattern - make a file with contents of specific pattern
lfbviewx
lfbviewx - framebuffer viewer for X
BUILD
-----
$ KOLIBRIOS=/path/to/kolibrios make
Linux:
$ KOLIBRIOS=/path/to/kolibrios HOST=linux CC=gcc make
/path/to/kolibrios is where you checked out 'svn co svn://kolibrios.org'.
Windows:
Same but specify HOST=windows and your favourite C compiler.
Architecture
------------
@ -69,7 +85,21 @@ Framebuffer can be dumped to disk as image file.
Testing
-------
sudo cp --parents /sys/firmware/acpi/tables/?SDT* /sys/bus/pci/devices/*/config .
# Run all the tests
$ HOST=linux make -B
# Copy ACPI tables and PCI configs
$ sudo cp --parents /sys/firmware/acpi/tables/?SDT* /sys/bus/pci/devices/*/config .
# Manage tap device
$ sudo ip tuntap add dev tap0 mode tap
$ sudo ip link set tap0 address 00:11:00:00:00:00
$ sudo ip addr add 10.50.0.1/24 dev tap0
$ sudo ip link set up dev tap0
$ sudo ip tuntap del dev tap0 mode tap
Troubleshooting
@ -83,19 +113,11 @@ Allow reading process_vm_readv syscall.
# umka_os
Managing tap devices.
# ip tuntap add dev tap0 mode tap
# ip link set tap0 address 00:11:00:00:00:00
# ip addr add 10.50.0.1/24 dev tap0
# ip link set up dev tap0
# ip tuntap del dev tap0 mode tap
To create tap devices.
# setcap cap_net_admin+ep ../umka_os
Not yet used, but may be one day.
To load apps at 0 address.
# sysctl -w vm.mmap_min_addr=0

2
umka.h
View File

@ -437,6 +437,8 @@ struct addrinfo {
typedef struct net_device_t net_device_t;
#define NET_BUFFER_SIZE 0x800
typedef struct {
void *next; // pointer to next frame in list
void *prev; // pointer to previous frame in list

View File

@ -164,7 +164,6 @@ main() {
kos_boot.pitch = UMKA_DEFAULT_DISPLAY_WIDTH*4; // 32bpp
umka_init();
dump_procs();
umka_stack_init();
FILE *f = fopen("../img/kolibri.img", "r");
@ -185,6 +184,7 @@ main() {
fprintf(stderr, "[net_drv] device %i: %s %u\n", i, devname, devtype);
}
// network setup should be done from the userspace app, e.g. via zeroconf
f76ret_t r76;
r76 = umka_sys_net_ipv4_set_subnet(1, inet_addr("255.255.255.0"));
if (r76.eax == (uint32_t)-1) {
@ -192,7 +192,6 @@ main() {
return -1;
}
// r76 = umka_sys_net_ipv4_set_gw(1, inet_addr("192.168.1.1"));
r76 = umka_sys_net_ipv4_set_gw(1, inet_addr("10.50.0.1"));
if (r76.eax == (uint32_t)-1) {
fprintf(stderr, "set gw error\n");
@ -213,7 +212,6 @@ main() {
thread_start(0, monitor, THREAD_STACK_SIZE);
// thread_start(0, umka_thread_net_drv, THREAD_STACK_SIZE);
dump_procs();

48
vnet.c
View File

@ -113,31 +113,30 @@ vnet_input(void *udata) {
net_device_t *vnet = udata;
vnet_userdata_t *u = vnet->userdata;
int tapfd = u->tapfd;
uint8_t buffer[2048];
int plen = 0;
fprintf(stderr, "###### vnet_input\n");
plen = read(tapfd, buffer, 2*1024);
if (plen > 0) {
fprintf(stderr, "[net_drv] read %i bytes\n", plen);
for (int i = 0; i < plen; i++) {
fprintf(stderr, " %2.2x", buffer[i]);
}
fprintf(stderr, "\n");
net_buff_t *buf = kos_net_buff_alloc(plen + offsetof(net_buff_t, data));
if (!buf) {
fprintf(stderr, "[vnet] Can't allocate network buffer!\n");
return 1;
}
buf->length = plen;
buf->device = vnet;
buf->offset = offsetof(net_buff_t, data);
memcpy(buf->data, buffer, plen);
kos_eth_input(buf);
fprintf(stderr, "[vnet] input interrupt\n");
net_buff_t *buf = kos_net_buff_alloc(NET_BUFFER_SIZE);
if (!buf) {
fprintf(stderr, "[vnet] Can't allocate network buffer!\n");
return 1;
}
buf->device = vnet;
plen = read(tapfd, buf->data, NET_BUFFER_SIZE - offsetof(net_buff_t, data));
if (plen == -1) {
plen = 0; // we have just allocated a buffer, so we have to submit it
}
fprintf(stderr, "[vnet] read %i bytes\n", plen);
for (int i = 0; i < plen; i++) {
fprintf(stderr, " %2.2x", buf->data[i]);
}
fprintf(stderr, "\n");
buf->length = plen;
buf->offset = offsetof(net_buff_t, data);
kos_eth_input(buf);
u->input_processed = true;
return 1;
return 1; // acknowledge our interrupt
}
static void
@ -234,12 +233,13 @@ vnet_init() {
};
kos_attach_int_handler(SIGUSR1, vnet_input, vnet);
fprintf(stderr, "### thread_start: %p\n", (void*)(uintptr_t)vnet_input_monitor);
fprintf(stderr, "[vnet] start input_monitor thread\n");
uint8_t *stack = malloc(STACK_SIZE);
size_t tid = umka_new_sys_threads(0, vnet_input_monitor, stack + STACK_SIZE);
appdata_t *t = kos_slot_base + tid;
*(void**)((uint8_t*)t->pl0_stack+0x2000-12) = vnet;
// t->saved_esp0 = (uint8_t*)t->saved_esp0 - 8;
*(void**)((uint8_t*)t->saved_esp0-12) = vnet; // param for monitor thread
// -12 here because in UMKa, unlike real hardware, we don't switch between
// kernel and userspace, i.e. stack structure is different
return vnet;
}