Add background related functions; umka_os works.

This commit is contained in:
Ivan Baravy 2020-05-11 06:38:44 +03:00
parent 532f440ec9
commit 57fadae3dd
10 changed files with 331 additions and 149 deletions

View File

@ -8,8 +8,8 @@ sigjmp_buf trampoline;
__attribute__((__stdcall__))
uint32_t umka_sched_add_thread(appdata_t *app) {
fprintf(stderr, "umka_new_sys_threads before\n");
fprintf(stderr, "kos_task_count: %d\n", kos_task_count);
// fprintf(stderr, "umka_new_sys_threads before\n");
// fprintf(stderr, "kos_task_count: %d\n", kos_task_count);
if (!sigsetjmp(trampoline, 1)) {
__asm__ __inline__ __volatile__ (
"pushfd;"
@ -29,7 +29,7 @@ uint32_t umka_sched_add_thread(appdata_t *app) {
: "memory");
}
}
fprintf(stderr, "umka_new_sys_threads after\n");
// fprintf(stderr, "umka_new_sys_threads after\n");
return 0;
}

108
shell.c
View File

@ -201,6 +201,7 @@ void prompt() {
fflush(fout);
}
/*
# define __FD_ZERO(fdsp) \
do { \
int __d0, __d1; \
@ -211,7 +212,7 @@ void prompt() {
"1" (&__FDS_BITS (fdsp)[0]) \
: "memory"); \
} while (0)
*/
int next_line(int is_tty, int block) {
if (is_tty) {
@ -221,7 +222,8 @@ int next_line(int is_tty, int block) {
return fgets(cmd_buf, FGETS_BUF_LEN, fin) != NULL;
} else {
fd_set readfds;
FD_ZERO(&readfds);
// FD_ZERO(&readfds);
memset(&readfds, 0, sizeof(readfds));
FD_SET(fileno(fin), &readfds);
struct timeval timeout = {.tv_sec = 0, .tv_usec = 0};
int sr = select(fileno(fin)+1, &readfds, NULL, NULL, &timeout);
@ -1676,6 +1678,101 @@ fprintf(fout, "## after\n");
}
}
void shell_bg_set_size(int argc, char **argv) {
const char *usage = \
"usage: bg_set_size <xsize> <ysize>\n"
" xsize in pixels\n"
" ysize in pixels";
if (argc != 3) {
puts(usage);
return;
}
uint32_t xsize = strtoul(argv[1], NULL, 0);
uint32_t ysize = strtoul(argv[2], NULL, 0);
umka_sys_bg_set_size(xsize, ysize);
}
void shell_bg_put_pixel(int argc, char **argv) {
const char *usage = \
"usage: bg_put_pixel <offset> <color>\n"
" offset in bytes, (x+y*xsize)*3\n"
" color in hex";
if (argc != 3) {
puts(usage);
return;
}
size_t offset = strtoul(argv[1], NULL, 0);
uint32_t color = strtoul(argv[2], NULL, 0);
umka_sys_bg_put_pixel(offset, color);
}
void shell_bg_redraw(int argc, char **argv) {
(void)argv;
const char *usage = \
"usage: bg_redraw";
if (argc != 1) {
puts(usage);
return;
}
umka_sys_bg_redraw();
}
void shell_bg_set_mode(int argc, char **argv) {
const char *usage = \
"usage: bg_set_mode <mode>\n"
" mode 1 = tile, 2 = stretch";
if (argc != 3) {
puts(usage);
return;
}
uint32_t mode = strtoul(argv[1], NULL, 0);
umka_sys_bg_set_mode(mode);
}
void shell_bg_put_img(int argc, char **argv) {
const char *usage = \
"usage: bg_put_img <image> <offset>\n"
" image file\n"
" offset in bytes, (x+y*xsize)*3\n";
if (argc != 4) {
puts(usage);
return;
}
FILE *f = fopen(argv[1], "r");
fseek(f, 0, SEEK_END);
size_t fsize = ftell(f);
rewind(f);
uint8_t *image = (uint8_t*)malloc(fsize);
fread(image, fsize, 1, f);
fclose(f);
size_t offset = strtoul(argv[2], NULL, 0);
umka_sys_bg_put_img(image, offset, fsize);
}
void shell_bg_map(int argc, char **argv) {
(void)argv;
const char *usage = \
"usage: bg_map";
if (argc != 1) {
puts(usage);
return;
}
void *addr = umka_sys_bg_map();
fprintf(fout, "%p\n", addr);
}
void shell_bg_unmap(int argc, char **argv) {
const char *usage = \
"usage: bg_unmap <addr>\n"
" addr return value of bg_map";
if (argc != 2) {
puts(usage);
return;
}
void *addr = (void*)strtoul(argv[1], NULL, 0);
uint32_t status = umka_sys_bg_unmap(addr);
fprintf(fout, "status = %d\n", status);
}
typedef struct {
char *name;
@ -1758,6 +1855,13 @@ func_table_t funcs[] = {
{ "net_arp_get_count", shell_net_arp_get_count },
{ "net_arp_get_entry", shell_net_arp_get_entry },
{ "net_arp_add_entry", shell_net_arp_add_entry },
{ "bg_set_size", shell_bg_set_size },
{ "bg_put_pixel", shell_bg_put_pixel },
{ "bg_redraw", shell_bg_redraw },
{ "bg_set_mode", shell_bg_set_mode },
{ "bg_put_img", shell_bg_put_img },
{ "bg_map", shell_bg_map },
{ "bg_unmap", shell_bg_unmap },
{ NULL, NULL },
};

View File

@ -3,7 +3,7 @@
/> set_skin /sys/DEFAULT.SKN
status: 0
/> window_redraw 1
/> draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
/> draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
/> set_pixel 1 1 0xff0000
/> set_pixel 2 2 0x00ff00
@ -21,7 +21,7 @@ status: 0
/> window_redraw 2
/> set_window_caption hi_there 0
/> move_window 220 35 150 200
/> get_font_smoothing
font smoothing: 2 - subpixel
/> set_font_smoothing 0
@ -41,15 +41,6 @@ font smoothing: 0 - off
0x007e7e7e work_graph
/> set_window_colors 0 0 0 0 0 0 0 0 0 0
/> window_redraw 1
/> draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
/> set_pixel 0 0 0x0000ff
/> set_pixel 1 1 0xff0000
/> set_pixel 2 2 0x00ff00
/> window_redraw 2
/> set_window_caption hi_2there 0
/> dump_win_stack 5
0: 0
1: 1
@ -67,13 +58,13 @@ font smoothing: 0 - off
cpu_usage: 0
window_stack_position: 2
window_stack_value: 2
process_name:
process_name: OS
memory_start: 0x00000000
used_memory: 4294967295 (0xffffffff)
pid: 0
box: 220 35 150 200
pid: 8
box: 10 5 300 200
slot_state: 0
client_box: 5 24 140 171
client_box: 5 24 290 171
wnd_state: 0x00
/> get_skin_height
24

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@ -1,7 +1,7 @@
disk_add ../img/kolibri.img rd -c 0
set_skin /sys/DEFAULT.SKN
window_redraw 1
draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
draw_window 10 300 5 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
set_pixel 1 1 0xff0000
set_pixel 2 2 0x00ff00
@ -19,7 +19,7 @@ blit_bitmap chess_image.rgba 20 35 8 8 0 0 8 8 0 0 0 1 32
window_redraw 2
set_window_caption hi_there 0
move_window 220 35 150 200
get_font_smoothing
set_font_smoothing 0
get_font_smoothing
@ -27,15 +27,6 @@ get_font_smoothing
get_window_colors
set_window_colors 0 0 0 0 0 0 0 0 0 0
window_redraw 1
draw_window 0 300 0 200 0x000088 1 1 1 0 1 4 hello
set_pixel 0 0 0x0000ff
set_pixel 1 1 0xff0000
set_pixel 2 2 0x00ff00
window_redraw 2
set_window_caption hi_2there 0
dump_win_stack 5
dump_win_pos 5

176
umka.asm
View File

@ -3,6 +3,14 @@ format ELF
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
UMKA_SHELL = 1
UMKA_FUSE = 2
UMKA_OS = 3
UMKA_MEMORY_BYTES = 128 SHL 20
UMKA_DISPLAY_WIDTH = 400
UMKA_DISPLAY_HEIGHT = 300
public disk_add
public disk_del
public disk_list
@ -43,6 +51,15 @@ public kos_acpi_ssdt_size
public stack_init
public net_add_device
public draw_data
public img_background
public BgrDataWidth
public BgrDataHeight
public mem_BACKGROUND
public sys_background
public REDRAW_BACKGROUND
public background_defined
macro cli {
pushfd
btr dword[esp], 21
@ -180,13 +197,12 @@ proc kos_init c uses ebx esi edi ebp
xor eax, eax
rep stosb
MEMORY_BYTES = 128 SHL 20
DISPLAY_WIDTH = 400
DISPLAY_HEIGHT = 300
mov [pg_data.mem_amount], MEMORY_BYTES
mov [pg_data.pages_count], MEMORY_BYTES / PAGE_SIZE
mov [pg_data.pages_free], MEMORY_BYTES / PAGE_SIZE
mov eax, MEMORY_BYTES SHR 12
mov [xsave_area_size], 0x1000
mov [pg_data.mem_amount], UMKA_MEMORY_BYTES
mov [pg_data.pages_count], UMKA_MEMORY_BYTES / PAGE_SIZE
mov [pg_data.pages_free], UMKA_MEMORY_BYTES / PAGE_SIZE
mov eax, UMKA_MEMORY_BYTES SHR 12
mov [pg_data.kernel_pages], eax
shr eax, 10
mov [pg_data.kernel_tables], eax
@ -199,9 +215,9 @@ proc kos_init c uses ebx esi edi ebp
list_init eax
mov [BOOT.bpp], 32
mov [BOOT.x_res], 400
mov [BOOT.y_res], 300
mov [BOOT.pitch], 400*4
mov [BOOT.x_res], UMKA_DISPLAY_WIDTH
mov [BOOT.y_res], UMKA_DISPLAY_HEIGHT
mov [BOOT.pitch], UMKA_DISPLAY_WIDTH*4
mov [BOOT.lfb], LFB_BASE
call init_video
@ -214,30 +230,6 @@ proc kos_init c uses ebx esi edi ebp
mov [srv.fd], eax
mov [srv.bk], eax
mov dword[sysdir_name], 'sys'
mov dword[sysdir_path], 'RD/1'
mov word[sysdir_path+4], 0
mov dword[CURRENT_TASK], 2
mov dword[TASK_COUNT], 2
mov dword[TASK_BASE], CURRENT_TASK + 2*sizeof.TASKDATA
mov [current_slot], SLOT_BASE + 256*2
;call ramdisk_init
mov ebx, SLOT_BASE + 2*256
stdcall kernel_alloc, 0x2000
mov [ebx+APPDATA.process], eax
mov word[cur_dir.path], '/'
mov [ebx+APPDATA.cur_dir], cur_dir
mov [ebx+APPDATA.wnd_clientbox.left], 0
mov [ebx+APPDATA.wnd_clientbox.top], 0
mov [X_UNDER], 500
mov [Y_UNDER], 500
mov word[MOUSE_X], 40
mov word[MOUSE_Y], 30
stdcall kernel_alloc, [_display.win_map_size]
mov [_display.win_map], eax
@ -261,43 +253,16 @@ proc kos_init c uses ebx esi edi ebp
@@:
mov [clipboard_main_list], eax
mov dword[sysdir_name], 'sys'
mov dword[sysdir_path], 'RD/1'
mov word[sysdir_path+4], 0
call set_window_defaults
call init_background
call calculatebackground
call init_display
mov eax, [def_cursor]
mov [SLOT_BASE+APPDATA.cursor+256], eax
mov [SLOT_BASE+APPDATA.cursor+256*2], eax
;call ramdisk_init
; from set_variables
xor eax, eax
mov [BTN_ADDR], dword BUTTON_INFO ; address of button list
mov byte [KEY_COUNT], al ; keyboard buffer
mov byte [BTN_COUNT], al ; button buffer
;call load_default_skin
;call stack_init
ret
endp
public skin_udata
proc idle uses ebx esi edi
.loop:
mov ecx, 10000000
@@:
loop @b
DEBUGF 1, "1 idle\n"
jmp .loop
ret
endp
extrn raise
public umka_os
proc umka_os uses ebx esi edi
call kos_init
mov [X_UNDER], 500
mov [Y_UNDER], 500
mov word[MOUSE_X], 40
mov word[MOUSE_Y], 30
mov eax, -1
mov edi, thr_slot_map+4
@ -315,22 +280,26 @@ proc umka_os uses ebx esi edi
mov dword[CURRENT_TASK], 0
mov dword[TASK_COUNT], 0
stdcall kernel_alloc, RING0_STACK_SIZE
mov eax, [xsave_area_size]
add eax, RING0_STACK_SIZE
stdcall kernel_alloc, eax
mov ebx, eax
mov edx, SLOT_BASE+256*1
call setup_os_slot
mov dword [edx], 'IDLE'
mov dword[edx], 'IDLE'
sub [edx+APPDATA.saved_esp], 4
mov eax, [edx+APPDATA.saved_esp]
mov dword[eax], idle ; _thread
mov dword[eax], idle
mov ecx, IDLE_PRIORITY
call sched_add_thread
stdcall kernel_alloc, RING0_STACK_SIZE
mov eax, [xsave_area_size]
add eax, RING0_STACK_SIZE
stdcall kernel_alloc, eax
mov ebx, eax
mov edx, SLOT_BASE+256*2
call setup_os_slot
mov dword [edx], 'OS'
mov dword[edx], 'OS'
sub [edx+APPDATA.saved_esp], 4
mov eax, [edx+APPDATA.saved_esp]
mov dword[eax], 0
@ -342,9 +311,45 @@ proc umka_os uses ebx esi edi
mov dword[TASK_BASE], CURRENT_TASK + 2*sizeof.TASKDATA
mov [current_slot], SLOT_BASE+256*2
; movi ebx, 1
; mov ecx, eth_process_input
; call new_sys_threads
call set_window_defaults
call init_background
call calculatebackground
call init_display
mov eax, [def_cursor]
mov [SLOT_BASE+APPDATA.cursor+256], eax
mov [SLOT_BASE+APPDATA.cursor+256*2], eax
; from set_variables
xor eax, eax
mov [BTN_ADDR], dword BUTTON_INFO ; address of button list
mov byte [KEY_COUNT], al ; keyboard buffer
mov byte [BTN_COUNT], al ; button buffer
mov ebx, SLOT_BASE + 2*256
mov word[cur_dir.path], '/'
mov [ebx+APPDATA.cur_dir], cur_dir
;call stack_init
ret
endp
public skin_udata
proc idle uses ebx esi edi
.loop:
mov ecx, 10000000
@@:
loop @b
; DEBUGF 1, "1 idle\n"
jmp .loop
ret
endp
extrn raise
public umka_os
proc umka_os uses ebx esi edi
call kos_init
call stack_init
@ -368,13 +373,6 @@ proc umka_os uses ebx esi edi
jmp osloop
.loop:
mov ecx, 10000000
@@:
loop @b
DEBUGF 1, "2 os\n"
jmp .loop
ret
endp
@ -426,12 +424,14 @@ sched_add_thread:
ret
change_task:
mov [REDRAW_BACKGROUND], 0
ret
public umka_install_thread
proc umka_install_thread _func
stdcall kernel_alloc, RING0_STACK_SIZE + 512 ; fpu_state
; fpu_state = sigsetjmp
mov eax, [xsave_area_size]
add eax, RING0_STACK_SIZE
stdcall kernel_alloc, eax
mov ebx, eax
mov edx, [TASK_COUNT]
inc edx
@ -523,7 +523,6 @@ map_memEx:
HEAP_BASE equ
include 'init.inc'
sys_msg_board equ __pew
;setup_os_slot equ ___pew
include fix pew
macro pew x {}
@ -555,7 +554,6 @@ macro add r, v {
end if
}
include 'kernel.asm'
purge lea,add,org
@ -566,6 +564,8 @@ coverage_end:
section '.data' writeable align 64
public umka_tool
umka_tool dd ?
timer_ticks dd 0
fpu_owner dd ?

82
umka.h
View File

@ -469,6 +469,11 @@ typedef struct {
uint32_t cpu_usage;
} taskdata_t;
#define UMKA_SHELL 1u
#define UMKA_FUSE 2u
#define UMKA_OS 3u
extern uint32_t umka_tool;
extern uint32_t kos_current_task;
extern appdata_t *kos_current_slot;
extern size_t kos_task_count;
@ -629,6 +634,83 @@ static inline void umka_sys_get_screen_size(uint32_t *xsize, uint32_t *ysize) {
*ysize = (xysize & 0xffffu) + 1;
}
static inline void umka_sys_bg_set_size(uint32_t xsize, uint32_t ysize) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(15),
"b"(1),
"c"(xsize),
"d"(ysize)
: "memory");
}
static inline void umka_sys_bg_put_pixel(uint32_t offset, uint32_t color) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(15),
"b"(2),
"c"(offset),
"d"(color)
: "memory");
}
static inline void umka_sys_bg_redraw() {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(15),
"b"(3)
: "memory");
}
static inline void umka_sys_bg_set_mode(uint32_t mode) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(15),
"b"(4),
"c"(mode)
: "memory");
}
static inline void umka_sys_bg_put_img(void *image, size_t offset,
size_t size) {
__asm__ __inline__ __volatile__ (
"call i40"
:
: "a"(15),
"b"(5),
"c"(image),
"d"(offset),
"S"(size)
: "memory");
}
static inline void *umka_sys_bg_map() {
void *addr;
__asm__ __inline__ __volatile__ (
"call i40"
: "=a"(addr)
: "a"(15),
"b"(6)
: "memory");
return addr;
}
static inline uint32_t umka_sys_bg_unmap(void *addr) {
uint32_t status;
__asm__ __inline__ __volatile__ (
"call i40"
: "=a"(status)
: "a"(15),
"b"(7),
"c"(addr)
: "memory");
return status;
}
static inline void umka_sys_set_cwd(const char *dir) {
__asm__ __inline__ __volatile__ (
"call i40"

View File

@ -64,7 +64,14 @@ static int umka_getattr(const char *path, struct stat *stbuf,
int res = 0;
bdfe_t file;
f7080s5arg_t fX0 = {.sf = 5, .flags = 0, .buf = &file, .u = {.f80 = {.path_encoding = UTF8, .path = path}}};
f7080s5arg_t fX0 = {.sf = 5,
.flags = 0,
.buf = &file,
.u = {.f80 = {.path_encoding = UTF8,
.path = path
}
}
};
f7080ret_t r;
umka_sys_lfn(&fX0, &r, F80);
@ -81,7 +88,16 @@ static int umka_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
(void) flags;
f7080s1info_t *dir = (f7080s1info_t*)malloc(sizeof(f7080s1info_t) + BDFE_LEN_UNICODE * DIRENTS_TO_READ);
f7080s1arg_t fX0 = {.sf = 1, .offset = 0, .encoding = UTF8, .size = DIRENTS_TO_READ, .buf = dir, .u = {.f80 = {.path_encoding = UTF8, .path = path}}};
f7080s1arg_t fX0 = {.sf = 1,
.offset = 0,
.encoding = UTF8,
.size = DIRENTS_TO_READ,
.buf = dir,
.u = {.f80 = {.path_encoding = UTF8,
.path = path
}
}
};
f7080ret_t r;
umka_sys_lfn(&fX0, &r, F80);
bdfe_t *bdfe = dir->bdfes;
@ -94,14 +110,14 @@ static int umka_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
}
static int umka_open(const char *path, struct fuse_file_info *fi) {
// if (strcmp(path+1, "blah") != 0)
// return -ENOENT;
(void) path;
// if (strcmp(path+1, "blah") != 0)
// return -ENOENT;
(void) path;
if ((fi->flags & O_ACCMODE) != O_RDONLY)
return -EACCES;
if ((fi->flags & O_ACCMODE) != O_RDONLY)
return -EACCES;
return 0;
return 0;
}
static int umka_read(const char *path, char *buf, size_t size, off_t offset,
@ -115,21 +131,22 @@ static int umka_read(const char *path, char *buf, size_t size, off_t offset,
}
static struct fuse_operations umka_oper = {
.init = umka_init,
.getattr = umka_getattr,
.readdir = umka_readdir,
.open = umka_open,
.read = umka_read,
.init = umka_init,
.getattr = umka_getattr,
.readdir = umka_readdir,
.open = umka_open,
.read = umka_read,
};
int main(int argc, char *argv[]) {
if (argc != 3) {
printf("usage: umka_fuse dir img\n");
exit(1);
}
kos_init();
void *userdata = vdisk_init(argv[2], 1, 0u);
void *vdisk = disk_add(&vdisk_functions, "hd0", userdata, 0);
disk_media_changed(vdisk, 1);
return fuse_main(argc-1, argv, &umka_oper, NULL);
umka_tool = UMKA_FUSE;
if (argc != 3) {
printf("usage: umka_fuse dir img\n");
exit(1);
}
kos_init();
void *userdata = vdisk_init(argv[2], 1, 0u);
void *vdisk = disk_add(&vdisk_functions, "hd0", userdata, 0);
disk_media_changed(vdisk, 1);
return fuse_main(argc-1, argv, &umka_oper, NULL);
}

View File

@ -22,7 +22,6 @@ void scheduler(int signo, siginfo_t *info, void *context) {
// printf("##### switching from task %u\n", kos_current_task);
ucontext_t *ctx = context;
if (!sigsetjmp(*kos_slot_base[kos_current_task].fpu_state, 1)) {
// printf("##### saved\n");
if (ctx->uc_mcontext.__gregs[REG_EFL] & (1 << 21)) {
kos_current_task += 1;
if (kos_current_task > kos_task_count) {
@ -33,36 +32,33 @@ void scheduler(int signo, siginfo_t *info, void *context) {
}
kos_current_slot = kos_slot_base + kos_current_task;
kos_task_base = ((taskdata_t*)&kos_current_task) + kos_current_task;
printf("##### kos_current_task: %u\n", kos_current_task);
// printf("##### kos_current_task: %u\n", kos_current_task);
setitimer(ITIMER_PROF, &timeout, NULL);
siglongjmp(*kos_slot_base[kos_current_task].fpu_state, 1);
}
}
//void intwrite(int fd,
void monitor() {
fprintf(stderr, "Start monitor thread\n");
// mkfifo("/tmp/umka.fifo.2u", 0644);
// mkfifo("/tmp/umka.fifo.4u", 0644);
FILE *fin = fopen("/tmp/umka.fifo.2u", "r");
FILE *fout = fopen("/tmp/umka.fifo.4u", "w");
// while (1) {
fprintf(stderr, "### from monitor: %d\n", fileno(fout));
// }
if (!fin || !fout) {
fprintf(stderr, "Can't open monitor files!\n");
return;
}
run_test(fin, fout, 0);
/*
while (1) {
for (int i = 0; i < 10000000; i++) {}
printf("6 monitor\n");
}
*/
}
int main() {
umka_tool = UMKA_OS;
struct sigaction sa;
sa.sa_sigaction = scheduler;

View File

@ -30,6 +30,7 @@
#include "trace.h"
int main(int argc, char **argv) {
umka_tool = UMKA_SHELL;
const char *usage = \
"usage: umka_shell [test_file.t] [-c]\n"
" -c collect coverage";