61,7 → 61,8 |
|
USE_COM_IRQ equ 1 ;make irq 3 and irq 4 available for PCI devices |
|
debug_com_base equ 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used, comment this line out to disable |
; Enabling the next line will enable serial output console |
;debug_com_base equ 0x3f8 ; 0x3f8 is com1, 0x2f8 is com2, 0x3e8 is com3, 0x2e8 is com4, no irq's are used |
|
include "proc32.inc" |
include "kglobals.inc" |
237,8 → 238,8 |
mov edi,0x2F0000 |
mov ecx,0x10000 / 4 |
rep movsd |
xor edi, edi |
mov ecx,0x10000 / 4 |
mov edi,0x1000 |
mov ecx,0xf000 / 4 |
rep stosd |
|
call test_cpu |
453,8 → 454,8 |
|
; LOAD IDT |
|
call build_interrupt_table |
lidt [idtreg] |
call build_interrupt_table ;lidt is executed |
;lidt [idtreg] |
|
call init_kernel_heap |
stdcall kernel_alloc, RING0_STACK_SIZE+512 |
548,9 → 549,8 |
mov [BgrDrawMode],eax |
mov [BgrDataWidth],eax |
mov [BgrDataHeight],eax |
mov [mem_BACKGROUND],4095 |
stdcall kernel_alloc, [mem_BACKGROUND] |
mov [img_background], eax |
mov [mem_BACKGROUND], 4 |
mov [img_background], static_background_data |
|
mov [SLOT_BASE + 256 + APPDATA.dir_table], sys_pgdir - OS_BASE |
|
674,8 → 674,8 |
|
xor eax, eax |
mov dword [SLOT_BASE+APPDATA.fpu_state], fpu_data |
mov dword [SLOT_BASE+APPDATA.fpu_handler], eax |
mov dword [SLOT_BASE+APPDATA.sse_handler], eax |
mov dword [SLOT_BASE+APPDATA.exc_handler], eax |
mov dword [SLOT_BASE+APPDATA.except_mask], eax |
|
; name for OS/IDLE process |
|
696,8 → 696,8 |
cld |
rep movsd |
|
mov dword [SLOT_BASE+256+APPDATA.fpu_handler], eax |
mov dword [SLOT_BASE+256+APPDATA.sse_handler], eax |
mov dword [SLOT_BASE+256+APPDATA.exc_handler], eax |
mov dword [SLOT_BASE+256+APPDATA.except_mask], eax |
|
mov ebx, SLOT_BASE+256+APP_OBJ_OFFSET |
mov dword [SLOT_BASE+256+APPDATA.fd_obj], ebx |
724,19 → 724,36 |
mov esi,boot_tsc |
call boot_log |
cli |
call _rdtsc |
rdtsc ;call _rdtsc |
mov ecx,eax |
mov esi,250 ; wait 1/4 a second |
call delay_ms |
call _rdtsc |
rdtsc ;call _rdtsc |
sti |
sub eax,ecx |
shl eax,2 |
mov [CPU_FREQ],eax ; save tsc / sec |
mov ebx, 1000000 |
div ebx |
mov [stall_mcs], eax |
; mov ebx, 1000000 |
; div ebx |
; ¢®®¡é¥-â® ¯à®¨§¢®¤¨â¥«ì®áâì ¢ ¤ ®¬ ª®ªà¥â®¬ ¬¥á⥠|
; ᮢ¥à襮 ¥ªà¨â¨ç , ® çâ®¡ë § âªãâì «î¡¨â¥«¥© |
; ®¯â¨¬¨§¨àãîé¨å ª®¬¯¨«ïâ®à®¢ ... |
mov edx, 2251799814 |
mul edx |
shr edx, 19 |
mov [stall_mcs], edx |
; PRINT CPU FREQUENCY |
mov esi, boot_cpufreq |
call boot_log |
|
mov ebx, edx |
movzx ecx, word [boot_y] |
add ecx, (10+17*6) shl 16 - 10 ; 'CPU frequency is ' |
mov edx, 0xFFFFFF |
mov edi, 1 |
mov eax, 0x00040000 |
call display_number_force |
|
; SET VARIABLES |
|
call set_variables |
745,7 → 762,7 |
|
;call detect_devices |
stdcall load_driver, szPS2MDriver |
stdcall load_driver, szCOM_MDriver |
; stdcall load_driver, szCOM_MDriver |
|
mov esi,boot_setmouse |
call boot_log |
789,9 → 806,7 |
stdcall map_page,tss._io_map_1,\ |
(tss._io_map_1-OS_BASE), PG_MAP |
|
mov ax,[OS_BASE+0x10000+bx_from_load] |
|
|
; LOAD FIRST APPLICATION |
cli |
|
989,58 → 1004,30 |
; MAIN OS LOOP END ; |
; ; |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
align 4 |
checkidle: |
pushad |
|
cmp [check_idle_semaphore],0 |
jne no_idle_state |
|
call change_task |
mov eax,[idlemem] |
mov ebx,[timer_ticks] ;[0xfdf0] |
cmp eax,ebx |
jnz idle_exit |
call _rdtsc |
jmp idle_loop_entry |
idle_loop: |
cmp eax,[idlemem] ; eax == [timer_ticks] |
jne idle_exit |
rdtsc ;call _rdtsc |
mov ecx,eax |
idle_loop: |
hlt |
rdtsc ;call _rdtsc |
sub eax,ecx |
add [idleuse],eax |
idle_loop_entry: |
mov eax,[timer_ticks] ; eax = [timer_ticks] |
cmp [check_idle_semaphore],0 |
jne idle_loop_exit |
mov eax,[timer_ticks] ;[0xfdf0] |
cmp ebx,eax |
jz idle_loop |
idle_loop_exit: |
mov [idlemem],eax |
call _rdtsc |
sub eax,ecx |
mov ebx,[idleuse] |
add ebx,eax |
mov [idleuse],ebx |
|
popad |
ret |
|
je idle_loop |
dec [check_idle_semaphore] |
idle_exit: |
|
mov ebx,[timer_ticks] ;[0xfdf0] |
mov [idlemem],ebx |
call change_task |
|
mov [idlemem],eax ; eax == [timer_ticks] |
popad |
ret |
|
no_idle_state: |
|
dec [check_idle_semaphore] |
|
mov ebx,[timer_ticks] ;[0xfdf0] |
mov [idlemem],ebx |
call change_task |
|
popad |
ret |
|
uglobal |
idlemem dd 0x0 |
idleuse dd 0x0 |
1146,7 → 1133,6 |
mov [BTN_ADDR],dword BUTTON_INFO ; address of button list |
|
;!! IP 04.02.2005: |
mov [next_usage_update], 100 |
mov byte [DONT_SWITCH], 0 ; change task if possible |
|
ret |
1306,6 → 1292,7 |
xor edx,edx |
call division_64_bits |
div ebx |
hexletters = __fdo_hexdigits |
add edx,hexletters |
mov dl,[edx] |
mov [edi],dl |
2261,8 → 2248,9 |
|
uglobal |
; bgrchanged dd 0x0 |
align 4 |
bgrlockpid dd 0 |
bgrlock db 0 |
bgrlockpid dd 0 |
endg |
|
sys_background: |
2274,10 → 2262,9 |
cmp edx,0 |
je sbgrr |
@@: |
mov al, 1 |
xchg [bgrlock], al |
test al, al |
jz @f |
;;Maxis use atomic bts for mutexes 4.4.2009 |
bts dword [bgrlock], 0 |
jnc @f |
call change_task |
jmp @b |
@@: |
2287,7 → 2274,11 |
|
pushad |
; return memory for old background |
stdcall kernel_free, [img_background] |
mov eax, [img_background] |
cmp eax, static_background_data |
jz @f |
stdcall kernel_free, eax |
@@: |
; calculate RAW size |
xor eax,eax |
inc eax |
2306,9 → 2297,18 |
; get memory for new background |
stdcall kernel_alloc, eax |
test eax, eax |
jz .exit_mem |
jz .memfailed |
mov [img_background], eax |
.exit_mem: |
jmp .exit |
.memfailed: |
; revert to static monotone data |
mov [img_background], static_background_data |
xor eax, eax |
inc eax |
mov [BgrDataWidth], eax |
mov [BgrDataHeight], eax |
mov [mem_BACKGROUND], 4 |
.exit: |
popad |
mov [bgrlock], 0 |
|
2320,20 → 2320,25 |
cmp ebx,2 ; SET PIXEL |
jnz nosb2 |
|
mov eax, [img_background] |
test ecx, ecx |
jz @f |
cmp eax, static_background_data |
jz .ret |
@@: |
mov ebx, [mem_BACKGROUND] |
add ebx, 4095 |
and ebx, -4096 |
sub ebx, 4 |
cmp ecx, ebx |
ja @F |
ja .ret |
|
mov eax,[img_background] |
mov ebx,[eax+ecx] |
and ebx,0xFF000000 ;255*256*256*256 |
and edx,0x00FFFFFF ;255*256*256+255*256+255 |
add edx,ebx |
mov [eax+ecx],edx |
@@: |
.ret: |
ret |
nosb2: |
|
2363,6 → 2368,13 |
|
cmp ebx,5 ; BLOCK MOVE TO BGR |
jnz nosb5 |
cmp [img_background], static_background_data |
jnz @f |
test edx, edx |
jnz .fin |
cmp esi, 4 |
ja .fin |
@@: |
; bughere |
mov eax, ecx |
mov ebx, edx |
2375,16 → 2387,17 |
|
cmp ebx, 6 |
jnz nosb6 |
;;Maxis use atomic bts for mutex 4.4.2009 |
@@: |
mov al, 1 |
xchg [bgrlock], al |
test al, al |
jz @f |
bts dword [bgrlock], 0 |
jnc @f |
call change_task |
jmp @b |
@@: |
mov eax, [CURRENT_TASK] |
mov [bgrlockpid], eax |
cmp [img_background], static_background_data |
jz .nomem |
stdcall user_alloc, [mem_BACKGROUND] |
mov [esp+32], eax |
test eax, eax |
2485,19 → 2498,24 |
cmp eax,2 ; PIXEL |
jnz nogb2 |
|
mov eax, [img_background] |
test ebx, ebx |
jz @f |
cmp eax, static_background_data |
jz .ret |
@@: |
mov ecx, [mem_BACKGROUND] |
add ecx, 4095 |
and ecx, -4096 |
sub ecx, 4 |
cmp ebx, ecx |
ja @F |
ja .ret |
|
mov eax,[img_background] |
mov eax,[ebx+eax] |
|
and eax, 0xFFFFFF |
mov [esp+36],eax |
@@: |
.ret: |
ret |
nogb2: |
|
3083,8 → 3101,6 |
|
call check_window_position |
|
call set_window_clientbox |
|
push ecx esi edi ; save for window fullscreen/resize |
;mov esi,edi |
|
3133,6 → 3149,8 |
mov [BTN_COUNT],byte 0 ; empty button buffer |
|
newd: |
call set_window_clientbox |
|
mov [edi+WDATA.fl_redraw],byte 0 ; no redraw |
mov edx,edi |
|
3649,14 → 3667,6 |
|
calculatebackground: ; background |
|
; all black |
|
mov edi, [img_background] ;IMG_BACKGROUND ; set background to black |
xor eax, eax |
mov ecx, 1023 ;0x0fff00 / 4 |
cld |
rep stosd |
|
mov edi,display_data ; set os to use all pixels |
mov eax,0x01010101 |
mov ecx,1280*1024 / 4 |
3705,7 → 3715,9 |
|
set_app_param: |
mov edi, [TASK_BASE] |
mov eax, [edi + TASKDATA.event_mask] |
mov [edi + TASKDATA.event_mask], ebx |
mov [esp+32], eax |
ret |
|
|
4648,7 → 4660,7 |
|
ret |
|
|
if used _rdtsc |
_rdtsc: |
bt [cpu_caps], CAPS_TSC |
jnc ret_rdtsc |
4658,6 → 4670,7 |
mov edx,0xffffffff |
mov eax,0xffffffff |
ret |
end if |
|
rerouteirqs: |
|
5350,7 → 5363,7 |
sys_apm: |
cmp word [apm_vf], 0 ; Check APM BIOS enable |
jne @f |
or [esp + 56], byte 1 ; error |
or [esp + 48], byte 1 ; error |
mov [esp + 36], dword 8 ; 32-bit protected-mode interface not supported |
ret |
|
5360,7 → 5373,7 |
|
cmp al, 3 |
ja @f |
and [esp + 56], byte 0xfe ; emulate func 0..3 as func 0 |
and [esp + 48], byte 0xfe ; emulate func 0..3 as func 0 |
mov eax, [apm_vf] |
mov [esp + 36], eax |
shr eax, 16 |
5390,8 → 5403,8 |
mov [esp + 32], ecx |
mov [esp + 36], eax |
setc al |
and [esp + 56], byte 0xfe |
or [esp + 56], al |
and [esp + 48], byte 0xfe |
or [esp + 48], al |
|
|
ret |
5443,7 → 5456,7 |
out 0x21, al |
out 0xA1, al |
|
if 1 |
if 0 |
mov word [OS_BASE+0x467+0],pr_mode_exit |
mov word [OS_BASE+0x467+2],0x1000 |
|
5456,6 → 5469,7 |
out 0x64,al |
|
hlt |
jmp $-1 |
|
else |
cmp byte [OS_BASE + 0x9030], 2 |
5507,6 → 5521,72 |
jmp no_acpi_power_off |
.fadt_found: |
; ebx is linear address of FADT |
mov edi, [ebx+40] ; physical address of the DSDT |
lea eax, [ebp+4000h] |
stdcall map_page, eax, edi, PG_MAP |
lea eax, [ebp+5000h] |
lea esi, [edi+0x1000] |
stdcall map_page, eax, esi, PG_MAP |
and esi, 0xFFF |
sub edi, esi |
cmp dword [esi+ebp+4000h], 'DSDT' |
jnz no_acpi_power_off |
mov eax, [esi+ebp+4004h] ; DSDT length |
sub eax, 36+4 |
jbe no_acpi_power_off |
add esi, 36 |
.scan_dsdt: |
cmp dword [esi+ebp+4000h], '_S5_' |
jnz .scan_dsdt_cont |
cmp byte [esi+ebp+4000h+4], 12h ; DefPackage opcode |
jnz .scan_dsdt_cont |
mov dl, [esi+ebp+4000h+6] |
cmp dl, 4 ; _S5_ package must contain 4 bytes |
; ...in theory; in practice, VirtualBox has 2 bytes |
ja .scan_dsdt_cont |
cmp dl, 1 |
jb .scan_dsdt_cont |
lea esi, [esi+ebp+4000h+7] |
xor ecx, ecx |
cmp byte [esi], 0 ; 0 means zero byte, 0Ah xx means byte xx |
jz @f |
cmp byte [esi], 0xA |
jnz no_acpi_power_off |
inc esi |
mov cl, [esi] |
@@: |
inc esi |
cmp dl, 2 |
jb @f |
cmp byte [esi], 0 |
jz @f |
cmp byte [esi], 0xA |
jnz no_acpi_power_off |
inc esi |
mov ch, [esi] |
@@: |
jmp do_acpi_power_off |
.scan_dsdt_cont: |
inc esi |
cmp esi, 0x1000 |
jb @f |
sub esi, 0x1000 |
add edi, 0x1000 |
push eax |
lea eax, [ebp+4000h] |
stdcall map_page, eax, edi, PG_MAP |
push PG_MAP |
lea eax, [edi+1000h] |
push eax |
lea eax, [ebp+5000h] |
push eax |
stdcall map_page |
pop eax |
@@: |
dec eax |
jnz .scan_dsdt |
jmp no_acpi_power_off |
do_acpi_power_off: |
mov edx, [ebx+48] |
test edx, edx |
jz .nosmi |
5518,10 → 5598,13 |
test al, 1 |
jz @b |
.nosmi: |
and cx, 0x0707 |
shl cx, 2 |
or cx, 0x2020 |
mov edx, [ebx+64] |
in ax, dx |
and ax, 203h |
or ax, 3C00h |
or ah, cl |
out dx, ax |
mov edx, [ebx+68] |
test edx, edx |
5528,7 → 5611,7 |
jz @f |
in ax, dx |
and ax, 203h |
or ax, 3C00h |
or ah, ch |
out dx, ax |
@@: |
jmp $ |
5547,6 → 5630,7 |
out 0x64,al |
|
hlt |
jmp $-1 |
|
scan_rsdp: |
add eax, OS_BASE |
5578,4 → 5662,3 |
|
uglobals_size = $ - endofcode |
diff16 "end of kernel code",0,$ |
|