umka/kolibri.asm

703 lines
17 KiB
NASM
Raw Normal View History

format ELF
__DEBUG__ = 1
2017-11-02 21:41:11 +01:00
__DEBUG_LEVEL__ = 1
extrn malloc
malloc fix __malloc
_malloc fix malloc
2018-06-13 03:29:17 +02:00
extrn free
free fix __free
_free fix free
2019-10-09 01:35:47 +02:00
sys_msg_board equ _sys_msg_board
2020-02-04 22:53:24 +01:00
cli equ nop
lang fix en
preboot_blogesc = 0 ; start immediately after bootlog
pci_code_sel = 0
VESA_1_2_VIDEO = 0 ; enable vesa 1.2 bank switch functions
2019-10-09 01:35:47 +02:00
purge mov,add,sub
purge mov,add,sub
2019-10-09 01:35:47 +02:00
section '.text' executable align 16
coverage_begin:
public coverage_begin
include 'macros.inc'
2020-02-04 22:53:24 +01:00
macro diff16 blah1,blah2,blah3 {
}
include 'proc32.inc'
include 'struct.inc'
include 'const.inc'
2020-02-04 22:53:24 +01:00
;OS_BASE = os_base
LFB_BASE = lfb_base
SLOT_BASE = os_base + 0x00080000
window_data = os_base + 0x00001000
WIN_STACK = os_base + 0x0000C000
WIN_POS = os_base + 0x0000C400
KEY_COUNT = os_base + 0x0000F400
KEY_BUFF = os_base + 0x0000F401 ; 120*2 + 2*2 = 244 bytes, actually 255 bytes
BTN_COUNT = os_base + 0x0000F500
BTN_BUFF = os_base + 0x0000F501
BTN_ADDR = os_base + 0x0000FE88
TASK_BASE = os_base + 0x00003010
CURRENT_TASK = os_base + 0x00003000
TASK_COUNT = os_base + 0x00003004
TASK_BASE = os_base + 0x00003010
include 'system.inc'
include 'fdo.inc'
2020-02-04 22:53:24 +01:00
; block and fs
include 'blkdev/disk.inc'
include 'blkdev/disk_cache.inc'
include 'fs/fs_lfn.inc'
include 'crc.inc'
2020-02-04 22:53:24 +01:00
; video
include 'core/dll.inc'
include 'video/framebuffer.inc'
include 'video/vesa20.inc'
include 'video/vga.inc'
include 'video/cursors.inc'
include 'unpacker.inc'
include 'gui/window.inc'
include 'gui/button.inc'
load_file equ __load_file
include 'gui/skincode.inc'
restore load_file
include 'gui/draw.inc'
include 'gui/font.inc'
include 'sha3.asm'
struct VDISK
File dd ?
SectCnt DQ ?
SectSize dd ? ; sector size
ends
public sha3_256_oneshot as 'hash_oneshot'
proc sha3_256_oneshot c uses ebx esi edi ebp, _ctx, _data, _len
stdcall sha3_256.oneshot, [_ctx], [_data], [_len]
ret
endp
2020-02-04 22:53:24 +01:00
align 4
syscall_getpixel: ; GetPixel
mov ecx, [_display.width]
xor edx, edx
mov eax, ebx
div ecx
mov ebx, edx
xchg eax, ebx
and ecx, 0xFBFFFFFF ;negate 0x04000000 use mouseunder area
call dword [GETPIXEL]; eax - x, ebx - y
mov [esp + 32], ecx
ret
align 4
calculate_fast_getting_offset_for_WinMapAddress:
; calculate data area for fast getting offset to _WinMapAddress
xor eax, eax
mov ecx, [_display.height]
mov edi, d_width_calc_area
cld
@@:
stosd
add eax, [_display.width]
dec ecx
jnz @r
ret
;------------------------------------------------------------------------------
align 4
calculate_fast_getting_offset_for_LFB:
; calculate data area for fast getting offset to LFB
xor eax, eax
mov ecx, [_display.height]
mov edi, BPSLine_calc_area
cld
@@:
stosd
add eax, [_display.lfb_pitch]
dec ecx
jnz @r
redrawscreen:
force_redraw_background:
ret
; TODO: move to trace_lbr
2019-10-09 01:35:47 +02:00
public set_eflags_tf
set_eflags_tf:
pushfd
pop eax
mov ecx, [esp + 4]
and ecx, 1
shl ecx, 8 ; TF
and eax, NOT (1 SHL 8)
or eax, ecx
push eax
popfd
ret
; TODO: move to trace_lwp
2019-10-09 01:35:47 +02:00
public get_lwp_event_size
get_lwp_event_size:
mov eax, 0x80000001
cpuid
bt ecx, 15
jnc .no_lwp
mov eax, 0x8000001c
cpuid
and eax, 1001b
cmp eax, 1001b
jnz .no_lwp
movzx eax, bh
ret
.no_lwp:
xor eax, eax
ret
public kos_getcwd
proc kos_getcwd c uses ebx esi edi ebp, _buf, _len
mov eax, 30
mov ebx, 2
mov ecx, [_buf]
mov edx, [_len]
call sys_current_directory
ret
endp
public kos_cd
proc kos_cd c uses ebx esi edi ebp, _path
mov eax, 30
mov ebx, 1
mov ecx, [_path]
call sys_current_directory
ret
endp
public kos_time_to_epoch
proc kos_time_to_epoch c uses ebx esi edi ebp, _time
mov esi, [_time]
call fsCalculateTime
add eax, 978307200 ; epoch to 2001.01.01
ret
endp
public kos_init
2020-02-04 22:53:24 +01:00
proc kos_init c uses ebx esi edi ebp
2019-10-09 01:35:47 +02:00
MEMORY_BYTES = 128 SHL 20
2020-02-04 22:53:24 +01:00
DISPLAY_WIDTH = 400
DISPLAY_HEIGHT = 300
2019-10-09 01:35:47 +02:00
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 dword[sysdir_name], 'sys'
mov dword[sysdir_path], 'HD0/'
mov word[sysdir_path+4], '1'
mov eax, SLOT_BASE + 2*256
2020-02-04 22:53:24 +01:00
mov [current_slot], eax
mov word[cur_dir.path], '/'
mov [eax+APPDATA.cur_dir], cur_dir
2020-02-04 22:53:24 +01:00
mov [eax+APPDATA.wnd_clientbox.left], 0
mov [eax+APPDATA.wnd_clientbox.top], 0
mov dword[CURRENT_TASK], 2
mov dword[TASK_COUNT], 2
mov dword[TASK_BASE], CURRENT_TASK + 2*sizeof.TASKDATA
mov [_display.x], 0
mov [_display.y], 0
mov [_display.width], DISPLAY_WIDTH
mov [_display.lfb_pitch], DISPLAY_WIDTH*4
mov [_display.height], DISPLAY_HEIGHT
mov [PUTPIXEL], Vesa20_putpixel32
mov [GETPIXEL], Vesa20_getpixel32
mov [_display.bytes_per_pixel], 4
mov [_display.bits_per_pixel], 32
mov [MOUSE_PICTURE], dword mousepointer
call calculate_fast_getting_offset_for_WinMapAddress
call calculate_fast_getting_offset_for_LFB
mov [X_UNDER], 500
mov [Y_UNDER], 500
mov word[MOUSE_X], 40
mov word[MOUSE_Y], 30
mov eax, [_display.width]
mul [_display.height]
mov [_display.win_map_size], eax
mov [_display.check_mouse], check_mouse_area_for_putpixel_new
mov [_display.check_m_pixel], check_mouse_area_for_getpixel_new
stdcall kernel_alloc, eax
mov [_display.win_map], eax
mov [BgrDrawMode], eax
mov [BgrDataWidth], eax
mov [BgrDataHeight], eax
mov [mem_BACKGROUND], 4
mov [img_background], static_background_data
; 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 set_window_defaults
mov [skin_data], 0
call load_default_skin
mov eax, 0
mov ebx, (0 SHL 16)+300
mov ecx, (0 SHL 16)+200
mov edx, 0x34000088
mov esi, 0x00008800
mov edi, window_title
call syscall_draw_window
mov eax, 1
mov ebx, 0
mov ecx, 0
mov edx, 0x000000ff
call syscall_setpixel
mov eax, 1
mov ebx, 1
mov ecx, 1
mov edx, 0x00ff0000
call syscall_setpixel
mov eax, 1
mov ebx, 2
mov ecx, 2
mov edx, 0x0000ff00
call syscall_setpixel
mov eax, 38
mov ebx, (10 SHL 16) + 510
mov ecx, (10 SHL 16) + 510
mov edx, 0x00ff0000
call syscall_drawline
mov eax, 13
mov ebx, (60 SHL 16) + 20
mov ecx, (30 SHL 16) + 20
mov edx, 0x0000ff00
call syscall_drawrect
mov eax, 7
mov ebx, chess_image
mov ecx, (8 SHL 16) + 8
mov edx, (5 SHL 16) + 15
call syscall_putimage
mov eax, 65
mov ebx, chess_image
mov ecx, (12 SHL 16) + 12
mov edx, (5 SHL 16) + 30
mov esi, 9
mov edi, 0
mov ebp, 0
call sys_putimage_palette
mov eax, 4
mov ebx, (10 SHL 16) + 70
mov ecx, 0xffff00
mov edx, window_title
mov esi, 5
mov edi, 0
call syscall_writetext
mov eax, 8
mov ebx, (55 SHL 16) + 40
mov ecx, (5 SHL 16) + 20
mov edx, 0x20c0ffee
mov esi, 0x00dddddd
call syscall_button
mov eax, 47
mov ebx, 0x80040000
mov ecx, 1234
mov edx, (5 SHL 16) + 45
mov esi, 0x50ffff00
mov edi, 0x000000ff
call display_number
ret
endp
2020-02-04 22:53:24 +01:00
window_title db 'hello',0
public kos_disk_add
proc kos_disk_add c uses ebx esi edi ebp, _file_name, _disk_name
extrn cio_disk_init
ccall cio_disk_init, [_file_name]
stdcall disk_add, vdisk_functions, [_disk_name], eax, DISK_NO_INSERT_NOTIFICATION
2018-05-14 09:54:05 +02:00
push eax
stdcall disk_media_changed, eax, 1
pop edx
movi ecx, 1
mov esi, [edx+DISK.Partitions]
.next_part:
cmp ecx, [edx+DISK.NumPartitions]
ja .part_done
DEBUGF 1, "/%s/%d: ", [edx+DISK.Name], ecx
lodsd
inc ecx
cmp [eax+PARTITION.FSUserFunctions], xfs._.user_functions
jnz @f
DEBUGF 1, "xfs\n"
jmp .next_part
@@:
cmp [eax+PARTITION.FSUserFunctions], ext_user_functions
jnz @f
DEBUGF 1, "ext\n"
jmp .next_part
@@:
cmp [eax+PARTITION.FSUserFunctions], fat_user_functions
jnz @f
DEBUGF 1, "fat\n"
jmp .next_part
@@:
cmp [eax+PARTITION.FSUserFunctions], ntfs_user_functions
jnz @f
DEBUGF 1, "ntfs\n"
jmp .next_part
@@:
DEBUGF 1, "???\n"
jmp .next_part
.part_done:
xor eax, eax
ret
.error:
movi eax, 1
ret
endp
public kos_disk_del
proc kos_disk_del c uses ebx esi edi ebp, _name
mov eax, [disk_list+LHEAD.next]
.next_disk:
cmp eax, disk_list
jz .not_found
mov esi, [eax+DISK.Name]
mov edi, [_name]
@@:
movzx ecx, byte[esi]
cmpsb
jnz .skip
jecxz .found
jmp @b
.skip:
mov eax, [eax+LHEAD.next]
jmp .next_disk
.found:
stdcall disk_del, eax
xor eax, eax
ret
.not_found:
movi eax, 1
ret
endp
public kos_lfn
proc kos_lfn c uses ebx edx esi edi ebp, _f7080arg, _f7080ret, _f70or80
push ebx
mov ebx, [_f7080arg]
pushad ; file_system_lfn writes here
cmp [_f70or80], 80
jz .f80
.f70:
call file_system_lfn
jmp .done
.f80:
call fileSystemUnicode
.done:
popad
mov ecx, [_f7080ret]
mov [ecx+0], eax ; status
mov [ecx+4], ebx ; count
pop ebx
2017-11-16 02:16:20 +01:00
ret
endp
2017-11-16 02:16:20 +01:00
proc vdisk_close stdcall uses ebx esi edi ebp, _userdata
extrn cio_disk_free
ccall cio_disk_free, [_userdata]
ret
endp
proc vdisk_read stdcall uses ebx esi edi ebp, _userdata, _buffer, _startsector:qword, _numsectors
extrn cio_disk_read
ccall cio_disk_read, [_userdata], [_buffer], dword[_startsector+0], dword[_startsector+4], [_numsectors]
movi eax, DISK_STATUS_OK
ret
endp
proc vdisk_write stdcall uses ebx esi edi ebp, userdata, buffer, startsector:qword, numsectors
extrn cio_disk_write
ccall cio_disk_write, [userdata], [buffer], dword[startsector+0], dword[startsector+4], [numsectors]
movi eax, DISK_STATUS_OK
ret
endp
proc vdisk_querymedia stdcall uses ebx esi edi ebp, vdisk, mediainfo
mov ecx, [mediainfo]
mov edx, [vdisk]
mov [ecx + DISKMEDIAINFO.Flags], 0
mov eax, [edx + VDISK.SectSize]
mov [ecx + DISKMEDIAINFO.SectorSize], eax
mov eax, [edx + VDISK.SectCnt.lo]
mov dword [ecx + DISKMEDIAINFO.Capacity + 0], eax
mov eax, [edx + VDISK.SectCnt.hi]
mov dword [ecx + DISKMEDIAINFO.Capacity + 4], eax
movi eax, DISK_STATUS_OK
ret
endp
proc __malloc
push ecx edx
ccall _malloc, eax
pop edx ecx
ret
endp
proc kernel_alloc _size
mov eax, [_size]
call malloc
ret
endp
proc alloc_kernel_space _size
mov eax, [_size]
call malloc
ret
endp
proc alloc_pages _cnt
mov eax, [_cnt]
shl eax, 12
call malloc
ret
endp
proc __free
2018-06-13 03:29:17 +02:00
ccall _free, eax
ret
endp
2018-06-13 03:29:17 +02:00
proc kernel_free base
mov eax, [base]
call free
xor eax, eax
ret
endp
proc _sys_msg_board
cmp cl, 0x0d
jz @f
pushad
mov eax, SYS_WRITE
mov ebx, STDOUT
push ecx
mov ecx, esp
mov edx, 1
int 0x80
pop ecx
popad
@@:
ret
endp
align 16 ;very often call this subrutine
memmove: ; memory move in bytes
; eax = from
; ebx = to
; ecx = no of bytes
test ecx, ecx
jle .ret
push esi edi ecx
mov edi, ebx
mov esi, eax
test ecx, not 11b
jz @f
push ecx
shr ecx, 2
rep movsd
pop ecx
and ecx, 11b
jz .finish
;--------------------------------------
align 4
@@:
rep movsb
;--------------------------------------
align 4
.finish:
pop ecx edi esi
;--------------------------------------
align 4
.ret:
ret
2020-02-04 22:53:24 +01:00
proc my_putpixel
DEBUGF 1,"hello from my putpixel!\n"
ret
endp
sys_msg_board_str:
protect_from_terminate:
unprotect_from_terminate:
change_task:
ReadCDWRetr:
WaitUnitReady:
prevent_medium_removal:
Read_TOC:
commit_pages:
release_pages:
fs_execute:
mutex_init:
mutex_lock:
mutex_unlock:
2020-02-04 22:53:24 +01:00
alloc_page:
map_page:
free_kernel_space:
cache_ide0:
cache_ide1:
wakeup_osloop:
read_process_memory:
.forced:
ret
2020-02-04 22:53:24 +01:00
proc __load_file _filename
push ebx ecx edx esi edi
stdcall kernel_alloc, skin_size
push eax
mov esi, skin
mov edi, eax
mov ecx, skin_size
rep movsb
pop eax
pop edi esi edx ecx ebx
ret
endp
2019-10-09 01:35:47 +02:00
coverage_end:
public coverage_end
2020-02-04 22:53:24 +01:00
section '.data' writeable align 64
include_debug_strings
vdisk_functions:
dd vdisk_functions_end - vdisk_functions
dd 0;vdisk_close ; close
dd 0 ; closemedia
dd vdisk_querymedia
dd vdisk_read
dd vdisk_write
dd 0 ; flush
dd 0 ; adjust_cache_size
vdisk_functions_end:
disk_name db 'hd0',0
2020-02-04 22:53:24 +01:00
;IncludeIGlobals
skin file 'skin.skn'
skin_size = $ - skin
include 'hid/mousedrv.inc'
include 'gui/mousepointer.inc'
screen_workarea RECT
display_width_standard dd 0
display_height_standard dd 0
do_not_touch_winmap db 0
window_minimize db 0
sound_flag db 0
chess_image db \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff, \
0x00,0x00,0x00, 0xff,0xff,0xff, 0x00,0x00,0x00, 0xff,0xff,0xff
fl_moving db 0
rb 3
;section '.bss' writeable align 16
;IncludeUGlobals
;section '.bss' writeable align 16
;IncludeUGlobals
; crap
DiskNumber db ?
ChannelNumber db ?
DevErrorCode dd ?
CDSectorAddress dd ?
CDDataBuf_pointer dd ?
2020-02-04 22:53:24 +01:00
;DRIVE_DATA: rb 0x4000
;cdpos dd ?
;cd_appl_data dd ?
;current_slot dd ?
;pg_data PG_DATA
ide_channel1_mutex MUTEX
ide_channel2_mutex MUTEX
ide_channel3_mutex MUTEX
ide_channel4_mutex MUTEX
ide_channel5_mutex MUTEX
ide_channel6_mutex MUTEX
ide_channel7_mutex MUTEX
ide_channel8_mutex MUTEX
2020-02-04 22:53:24 +01:00
os_base rb 0x400000
public lfb_base_addr as 'kos_lfb_base'
lfb_base_addr dd lfb_base
lfb_base rd MAX_SCREEN_WIDTH*MAX_SCREEN_HEIGHT
cur_dir:
.encoding rb 1
.path rb maxPathLength
2020-02-04 22:53:24 +01:00
BgrAuxTable rb 32768
BgrAuxTable equ
SB16Buffer rb 65536
SB16Buffer equ
BUTTON_INFO rb 64*1024
BUTTON_INFO equ
include 'data32.inc'