From f4fbaa166ed0e7e407c0c8b33ebc9cbdf69699cf Mon Sep 17 00:00:00 2001 From: "Andrey Halyavin (halyavin)" Date: Wed, 25 Jan 2006 13:19:21 +0000 Subject: [PATCH] *Reduced size of boot code. (diamond) *Debug API added. (diamond) git-svn-id: svn://kolibrios.org@40 a494cfbc-eb01-0410-851d-a64ba20cac60 --- kernel/trunk/boot/bootcode.inc | 276 ++++++++++---------------- kernel/trunk/boot/booteng.inc | 47 +++-- kernel/trunk/boot/bootru.inc | 48 +++-- kernel/trunk/core/debug.inc | 344 +++++++++++++++++++++++++++++++++ kernel/trunk/core/newproce.inc | 13 ++ kernel/trunk/core/sched.inc | 11 +- kernel/trunk/core/sys32.inc | 130 +++++++++---- kernel/trunk/core/syscall.inc | 3 +- kernel/trunk/fs/fs.inc | 3 + kernel/trunk/gui/event.inc | 12 ++ kernel/trunk/hid/keyboard.inc | 6 +- kernel/trunk/kernel.asm | 10 +- 12 files changed, 641 insertions(+), 262 deletions(-) create mode 100644 kernel/trunk/core/debug.inc diff --git a/kernel/trunk/boot/bootcode.inc b/kernel/trunk/boot/bootcode.inc index 09926a8932..c478d7c7c7 100644 --- a/kernel/trunk/boot/bootcode.inc +++ b/kernel/trunk/boot/bootcode.inc @@ -139,6 +139,14 @@ macro _setcursor row,column call setcursor } +pagetable_set: + or al, 7 +@@: + stosd + add eax, 1000h + loop @b + ret + ; 16-bit data ; videomodes table gr_table: @@ -275,6 +283,7 @@ dfl1: cmp ax,dx jnz cpugood mov si,not386-0x10000 +sayerr: call print jmp $ cpugood: @@ -347,9 +356,9 @@ wait_loop: ; variant 2 jnz @f mov ax,[es:di+4] add ax,'0'*256+'0' - mov [vervesa+vervesa_off-0x10000], ah - mov [vervesa+vervesa_off+2-0x10000], al - mov si,vervesa-0x10000 + mov si,vervesa-0x10000 + mov [si+vervesa_off], ah + mov [si+vervesa_off+2], al @@: call print ; \begin{diamond}[30.11.2005] @@ -360,36 +369,33 @@ cfgmanager: ; b) preboot_mtrr = use hardware acceleration? ; c) preboot_vrrm = use VRR? ; d) preboot_device = from what boot? - mov si, preboot_graph-0x10000 + mov di, preboot_graph-0x10000 ; check bootloader block cmp [.loader_block-0x10000], 0 jz .noloaderblock les bx, [.loader_block-0x10000] cmp byte [es:bx], 1 - jz @f mov si, loader_block_error-0x10000 - call print - jmp $ -@@: + jnz sayerr test byte [es:bx+1], 1 jz @f ; image in memory present - cmp [si+preboot_device-preboot_graph], 0 + cmp [di+preboot_device-preboot_graph], 0 jnz @f - mov [si+preboot_device-preboot_graph], 3 + mov [di+preboot_device-preboot_graph], 3 @@: .noloaderblock: ; determine default settings mov [.bSettingsChanged-0x10000], 0 - cmp byte [si], 0 + cmp byte [di], 0 jnz .preboot_gr_end - mov [si+preboot_gprobe-preboot_graph], 0 + mov [di+preboot_gprobe-preboot_graph], 0 mov al, [vervesa+vervesa_off-0x10000] cmp al, 'x' jz .novesa cmp al, '1' jz .vesa12 - mov [si+preboot_gprobe-preboot_graph], 2 + mov [di+preboot_gprobe-preboot_graph], 2 mov al, 3 jmp @f .vesa12: @@ -398,14 +404,14 @@ cfgmanager: .novesa: mov al, 10 @@: - mov [si], al + mov [di], al .preboot_gr_end: - cmp [si+preboot_mtrr-preboot_graph], 1 - adc [si+preboot_mtrr-preboot_graph], 0 - cmp [si+preboot_vrrm-preboot_graph], 1 - adc [si+preboot_vrrm-preboot_graph], 0 - cmp [si+preboot_device-preboot_graph], 1 - adc [si+preboot_device-preboot_graph], 0 + cmp [di+preboot_mtrr-preboot_graph], 1 + adc [di+preboot_mtrr-preboot_graph], 0 + cmp [di+preboot_vrrm-preboot_graph], 1 + adc [di+preboot_vrrm-preboot_graph], 0 + cmp [di+preboot_device-preboot_graph], 1 + adc [di+preboot_device-preboot_graph], 0 ; notify user mov si, linef-0x10000 call print @@ -457,21 +463,11 @@ cfgmanager: mov si, linef-0x10000 call printplain mov si, mtrr_msg-0x10000 - call print - mov si, on_msg-0x10000 cmp [preboot_mtrr-0x10000], 1 - jz @f - mov si, off_msg-0x10000 -@@: - call printplain + call .say_on_off mov si, vrrm_msg-0x10000 - call print - mov si, on_msg-0x10000 cmp [preboot_vrrm-0x10000], 1 - jz @f - mov si, off_msg-0x10000 -@@: - call printplain + call .say_on_off mov si, preboot_device_msg-0x10000 call print mov al, [preboot_device-0x10000] @@ -479,7 +475,6 @@ cfgmanager: mov si, [preboot_device_msgs-0x10000+eax*2] call printplain .wait: -; empty BIOS keyboard buffer _setcursor 25,0 ; out of screen ; set timer interrupt handler cli @@ -497,9 +492,9 @@ cfgmanager: ; restore timer interrupt push 0 pop es - mov ecx, [.oldtimer-0x10000] - mov [es:8*4], ecx - mov [.timer-0x10000], ecx + mov eax, [.oldtimer-0x10000] + mov [es:8*4], eax + mov [.timer-0x10000], eax _setcursor 7,0 mov si, space_msg-0x10000 call printplain @@ -518,13 +513,13 @@ cfgmanager: jnz .wait _setcursor 15,0 mov si,bdev-0x10000 - call printplain + call print mov bx,'13' call getkey mov [preboot_device-0x10000], al _setcursor 13,0 .d: - mov [.bSettingsChanged-0x10000], al + mov [.bSettingsChanged-0x10000], 1 mov si, space_msg-0x10000 call printplain _setcursor 15,0 @@ -553,7 +548,7 @@ cfgmanager: .change_b: _setcursor 15,0 mov si, gr_acc-0x10000 - call printplain + call print mov bx, '12' call getkey mov [preboot_mtrr-0x10000], al @@ -562,16 +557,28 @@ cfgmanager: .change_c: _setcursor 15,0 mov si, vrrmprint-0x10000 - call printplain + call print mov bx, '12' call getkey mov [preboot_vrrm-0x10000], al _setcursor 12,0 jmp .d +.say_on_off: + pushf + call print + mov si, on_msg-0x10000 + popf + jz @f + mov si, off_msg-0x10000 +@@: call printplain + ret +; novesa and vervesa strings are not used at the moment of executing this code +virtual at novesa .oldtimer dd ? .starttime dd ? .bSettingsChanged db ? .timer dd ? +end virtual .loader_block dd 0 .gettime: mov ah, 0 @@ -672,9 +679,9 @@ end if .cont: push cs pop ds - mov byte [space_msg-0x10000+80], 0 - _setcursor 15,0 mov si, space_msg-0x10000 + mov byte [si+80], 0 + _setcursor 15,0 call printplain _setcursor 15,0 .load: @@ -683,13 +690,6 @@ end if ; ASK GRAPHICS MODE movzx ax, [preboot_graph-0x10000] - test ax, ax - jne pre_graph - mov si,gr_mode-0x10000 - call printplain - mov bx,'09' - call getkey - pre_graph: push 0 pop es ; address is gr_table+6*(ax-1)-0x10000 @@ -699,77 +699,51 @@ end if mov cx,[si+2] mov dx,[si+4] cmp al, 9*2 + mov al, 32 ; BPP jb @f - mov byte [es:0x9000], 32 + mov [es:0x9000], al mov dword [es:0x9018], 0x800000 @@: mov [es:0x9008],bx mov [es:0x900A],cx mov [es:0x900C],dx - mov ax,32 test bh, bh jz nov ; USE DEFAULTS OR PROBE ; bx - mode : cx - x size : dx - y size - - ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - movzx ax,[preboot_gprobe-0x10000] - test ax,ax - jne pre_probe - ;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - test bx,0100000000000000b - jz noprobe - - mov si,probetext-0x10000 - call printplain - push bx - mov bx, '12' - call getkey - pop bx - - pre_probe: - dec ax - je noprobe - - push cx dx + cmp [preboot_gprobe-0x10000], 1 + jz noprobe mov bx,0x100 - newprobe: - inc bx cmp bx,0x17f - jne probemore - - mov si,prnotfnd-0x10000 - call printplain - - jmp $ + mov si,prnotfnd-0x10000 + jz sayerr probemore: - + push cx mov ax,0x4f01 mov cx,bx and cx,0xfff mov di,0xa000 int 0x10 + pop cx test byte [es:di], 80h ; lfb? jz newprobe - mov ax, [es:di+0x12] ; x size? - cmp ax, [esp+2] + cmp [es:di+0x12], cx ; x size? jnz newprobe cmp [es:di+0x14], dx ; y size? jnz newprobe cmp byte [es:di+0x19], 32 ;24 jb newprobe - add bx,0100000000000000b +; add bx,0100000000000000b + or bh, 40h mov [es:0x9008],bx - pop dx cx noprobe: @@ -782,27 +756,26 @@ end if mov di,0xa000 int 0x10 ; LFB - mov ecx,[es:di+0x28] - mov [es:0x9018],ecx + mov eax,[es:di+0x28] + mov [es:0x9018],eax ; ---- vbe voodoo BytesPerScanLine equ 0x10 mov ax, [es:di+BytesPerScanLine] mov [es:0x9001],ax ; BPP - movzx ax,byte [es:di+0x19] + mov al,byte [es:di+0x19] mov [es:0x9000],al nov: - cmp ax,24 + cmp al,24 mov si,bt24-0x10000 jz bppl - cmp ax,32 + cmp al,32 mov si,bt32-0x10000 jz bppl mov si,btns-0x10000 - call print - jmp $ + jmp sayerr bppl: - call printplain + call print ; FIND VESA 1.2 PM BANK SWITCH ADDRESS @@ -825,33 +798,12 @@ end if ; GRAPHICS ACCELERATION mov al, [preboot_mtrr-0x10000] - test al,al - jne pre_mtrr - mov si,gr_acc-0x10000 - call printplain - mov bx,'12' - call getkey - pre_mtrr: mov [es:0x901C],al -; commented by diamond - newlines are not used now -; mov si,linef-0x10000 -; call printplain - ; VRR_M USE mov al,[preboot_vrrm-0x10000] - test al,al - jne pre_vrrm - mov si,vrrmprint-0x10000 - call print - mov bx,'13' - call getkey - pre_vrrm: mov [es:0x9030],al -; commented by diamond - newlines are not used now -; mov si,linef2-0x10000 -; call printplain ; MEMORY MODEL @@ -939,24 +891,12 @@ end if ; BOOT DEVICE mov al, [preboot_device-0x10000] - test al, al - jnz pre_device - mov si,bdev-0x10000 - call printplain - mov bx,'13' - call getkey - pre_device: - dec ax + dec al mov [boot_dev-0x10000],al -; commented by diamond - newlines are not used now -; mov si,linef-0x10000 -; call printplain - - ; READ DISKETTE TO MEMORY - cmp [boot_dev-0x10000],0 +; cmp [boot_dev-0x10000],0 jne no_sys_on_floppy mov si,diskload-0x10000 call print @@ -979,6 +919,7 @@ end if cmp si,10 jnz newread mov si,badsect-0x10000 +sayerr_plain: call printplain jmp $ goodread: @@ -998,8 +939,7 @@ end if mov al,0 out dx,al mov si,memmovefailed-0x10000 - call print - jmp $ + jmp sayerr_plain goodmove: add dword [movedesc-0x10000+0x18+2], 512*18 @@ -1030,8 +970,7 @@ end if jnz reads readdone: pop ax - mov si,backspace-0x10000 - call printplain + mov si,backspace2-0x10000 call printplain mov si,okt-0x10000 call printplain @@ -1054,30 +993,36 @@ end if pop es ; es:di = 6000:0 xor di,di mov cx,256*map_mem ; Map (mapmem) M - mov eax,7 - pt2: - cmp cx,256*(map_mem-8) ; 8 M map to LFB - jnz pt3 - pop eax - add eax,7 - pt3: - cmp cx,256*(map_mem-12) ; 12 M back to linear = physical - jnz pt4 - mov eax,12*0x100000 + 7 - pt4: - stosd - add eax,4096 - loop pt2 - +; mov eax,7 +; pt2: +; cmp cx,256*(map_mem-8) ; 8 M map to LFB +; jnz pt3 +; pop eax +; add eax,7 +; pt3: +; cmp cx,256*(map_mem-12) ; 12 M back to linear = physical +; jnz pt4 +; mov eax,12*0x100000 + 7 +; pt4: +; stosd +; add eax,4096 +; loop pt2 +; initialize as identity mapping + xor eax, eax + call pagetable_set +; 8M..12M map to LFB + pop eax +; mov cx, 256*4 + mov ch, 4 + mov di, 2000h + call pagetable_set + push 0x7100 pop es xor di,di - mov eax,8*0x100000+7 + mov eax,8*0x100000 mov cx,256*4 - pt5: - stosd - add eax,0x1000 - loop pt5 + call pagetable_set ; 4 KB PAGE DIRECTORY @@ -1086,15 +1031,12 @@ end if xor di, di mov cx, 64 / 4 mov eax, 0x60007 ; for 0 M - pd4k: - stosd - add eax, 0x1000 - loop pd4k + call pagetable_set mov dword [es:0x800],0x71007 ;map region 0x80000000-0x803FFFFF to 0x800000-0xCFFFFF xor si,si mov di,second_base_address shr 20 - mov cx,64/4 - rep movs dword [es:di], [es:si] + mov cx,64/2 + rep movs word [es:di], [es:si] mov eax, 0x7F000 +8+16 ; Page directory and enable caches mov cr3, eax @@ -1102,9 +1044,8 @@ end if ; SET GRAPHICS pop es - mov bx,[es:0x9008] ; vga & 320x200 - mov ax, bx - push ax + mov ax,[es:0x9008] ; vga & 320x200 + mov bx, ax cmp ax,0x13 je setgr cmp ax,0x12 @@ -1113,18 +1054,15 @@ end if setgr: int 0x10 test ah,ah - jz gmok - mov si,fatalsel-0x10000 - call print - jmp $ - - gmok: + mov si, fatalsel-0x10000 + jnz sayerr ; set mode 0x12 graphics registers: cmp bx,0x12 jne gmok2 mov al,0x05 mov dx,0x03ce + push dx out dx,al ; select GDC mode register mov al,0x02 inc dx @@ -1138,7 +1076,7 @@ end if out dx,al ; set mask for all planes 0-3 mov al,0x08 - mov dx,0x03ce + pop dx out dx,al ; select GDC bit mask register ; for writes to 0x03cf diff --git a/kernel/trunk/boot/booteng.inc b/kernel/trunk/boot/booteng.inc index b059411d76..cfcd49dde2 100644 --- a/kernel/trunk/boot/booteng.inc +++ b/kernel/trunk/boot/booteng.inc @@ -53,7 +53,7 @@ d80x25_bottom: d80x25_bottom_num = 3 novesa db "Display: EGA/CGA",13,10,0 -vervesa db "Version of Vesa: Vesa x.x ",13,10,0 +vervesa db "Version of Vesa: Vesa x.x",13,10,0 vervesa_off=22 gr_mode db 186," Vesa 2.0+ 16 M LFB: [1] 640x480, [2] 800x600, " db "[3] 1024x768, [4] 1280x1024",13,10 @@ -62,25 +62,24 @@ gr_mode db 186," Vesa 2.0+ 16 M LFB: [1] 640x480, [2] 800x600, " db 186," EGA/CGA 256 Colors: [9] 320x200, " db "VGA 16 Colors: [0] 640x480",13,10 db 186," Select mode: ",0 -bt24 db 13,10,186," Bits Per Pixel: 24",13,10,0 -bt32 db 13,10,186," Bits Per Pixel: 32",13,10,0 -vrrmprint db 13,10,186," Apply VRR? (picture frequency greater than 60Hz" +bt24 db "Bits Per Pixel: 24",13,10,0 +bt32 db "Bits Per Pixel: 32",13,10,0 +vrrmprint db "Apply VRR? (picture frequency greater than 60Hz" db " only for transfers:",13,10 db 186," 1024*768->800*600 and 800*600->640*480) [1-yes,2-no]:",0 -askmouse db " Mouse at:" - db " [1] PS/2 (USB), [2] Com1, [3] Com2." - db " Select port [1-3]: ",0 -no_com1 db 13,10,186, " No COM1 mouse",0 -no_com2 db 13,10,186, " No COM2 mouse",0 -gr_acc db 13,10,186," Vesa 2.0+ : MTRR graphics acceleration " - db "[1-yes/2-no] ? ",0 -gr_direct db 186," Use direct LFB writing? " +;askmouse db " Mouse at:" +; db " [1] PS/2 (USB), [2] Com1, [3] Com2." +; db " Select port [1-3]: ",0 +;no_com1 db 13,10,186, " No COM1 mouse",0 +;no_com2 db 13,10,186, " No COM2 mouse",0 +gr_acc db "Vesa 2.0+ : MTRR graphics acceleration " db "[1-yes/2-no] ? ",0 +;gr_direct db 186," Use direct LFB writing? " +; db "[1-yes/2-no] ? ",0 ;mem_model db 13,10,186," Motherboard memory [1-16 Mb / 2-32 Mb / " ; db "3-64Mb / 4-128 Mb / 5-256 Mb] ? ",0 -bootlog db 13,10,186," After bootlog display [1-continue/2-pause] ? ",0 -bdev db 186 - db " Load ramdisk from [1-floppy; 2-C:\menuet.img (FAT32);" +;bootlog db 13,10,186," After bootlog display [1-continue/2-pause] ? ",0 +bdev db "Load ramdisk from [1-floppy; 2-C:\menuet.img (FAT32);" db 13,10,186," " db "3-use preloaded ram-image from kernel restart]: ",0 probetext db 13,10,13,10,186," Use standart graphics mode? [1-yes, " @@ -90,18 +89,18 @@ probetext db 13,10,13,10,186," Use standart graphics mode? [1-yes, " ;memokz64 db 13,10,186," RAM 64 Mb",0 ;memokz32 db 13,10,186," RAM 32 Mb",0 ;memokz16 db 13,10,186," RAM 16 Mb",0 -prnotfnd db " pr. - not found.",0 -modena db "Fatal - VBE 0x112+ required.",0 +prnotfnd db "Fatal - Videomode not found.",0 +;modena db "Fatal - VBE 0x112+ required.",0 not386 db "Fatal - CPU 386+ required.",0 -btns db 13,10,186,"Fatal - Can't determine color depth.",0 -fatalsel db 13,10,"Fatal - Graphics mode not supported by hardware.",0 -badsect db 13,10,186," Fatal - Bad sector. Replace floppy. ",0 -memmovefailed db "Fatal - Int 0x15 move failed.",0 +btns db "Fatal - Can't determine color depth.",0 +fatalsel db "Fatal - Graphics mode not supported by hardware.",0 +badsect db 13,10,186," Fatal - Bad sector. Replace floppy.",0 +memmovefailed db 13,10,186," Fatal - Int 0x15 move failed.",0 okt db " ... OK" linef db 13,10,0 -diskload db 13,10,186," Loading diskette: 00 %",8,8,8,8,0 -backspace db 8,0 -pros db "00",8,8,0 +diskload db "Loading diskette: 00 %",8,8,8,8,0 +pros db "00" +backspace2 db 8,8,0 boot_dev db 0 ; 0=floppy, 1=hd start_msg db "Press [abcd] to change settings, press [Enter] to continue booting",13,10,0 time_msg db " or wait " diff --git a/kernel/trunk/boot/bootru.inc b/kernel/trunk/boot/bootru.inc index 881e75e0d8..584bf169e3 100644 --- a/kernel/trunk/boot/bootru.inc +++ b/kernel/trunk/boot/bootru.inc @@ -53,7 +53,7 @@ d80x25_bottom: d80x25_bottom_num = 3 novesa db "Видеокарта: EGA/CGA",13,10,0 -vervesa db "Версия VESA: Vesa x.x ",13,10,0 +vervesa db "Версия VESA: Vesa x.x",13,10,0 vervesa_off=19 gr_mode db 186," Vesa 2.0+ 16 M LFB: [1] 640x480, [2] 800x600, " db "[3] 1024x768, [4] 1280x1024",13,10 @@ -62,25 +62,24 @@ gr_mode db 186," Vesa 2.0+ 16 M LFB: [1] 640x480, [2] 800x600, " db 186," EGA/CGA 256 Цветов: [9] 320x200, " db "VGA 16 Цветов: [0] 640x480",13,10 db 186," Выберите видеорежим: ",0 -bt24 db 13,10,186," Глубина цвета: 24",13,10,0 -bt32 db 13,10,186," Глубина цвета: 32",13,10,0 -vrrmprint db 13,10,186," Использовать VRR? (частота кадров выше 60 Гц" +bt24 db "Глубина цвета: 24",13,10,0 +bt32 db "Глубина цвета: 32",13,10,0 +vrrmprint db "Использовать VRR? (частота кадров выше 60 Гц" db " только для переходов:",13,10 db 186," 1024*768>800*600 и 800*600>640*480) [1-да, 2-нет]: ",0 -askmouse db "Мышь:" ; 186, " " - db " [1] PS/2 (USB), [2] Com1, [3] Com2." - db " Выберите порт [1-3]: ",0 -no_com1 db 13,10,186," No COM1 mouse",0 -no_com2 db 13,10,186," No COM2 mouse",0 -gr_acc db 13,10,186," Vesa 2.0+: Включить MTRR для ускорения графики? " - db "[1-да/2-нет]: ",0 -gr_direct db 186," Использовать линейный видеобуфер? " +;askmouse db "Мышь:" ; 186, " " +; db " [1] PS/2 (USB), [2] Com1, [3] Com2." +; db " Выберите порт [1-3]: ",0 +;no_com1 db 13,10,186," No COM1 mouse",0 +;no_com2 db 13,10,186," No COM2 mouse",0 +gr_acc db "Vesa 2.0+: Включить MTRR для ускорения графики? " db "[1-да/2-нет]: ",0 +;gr_direct db 186," Использовать линейный видеобуфер? " +; db "[1-да/2-нет]: ",0 ;mem_model db 13,10,186," Объ+м памяти [1-16 Mb / 2-32 Mb / " ; db "3-64Mb / 4-128 Mb / 5-256 Mb]: ",0 -bootlog db 13,10,186," Просмотреть журнал загрузки? [1-нет/2-да]: ",0 -bdev db 186 - db " Загрузить образ из [1-дискета; 2-C:\menuet.img (FAT32);" +;bootlog db 13,10,186," Просмотреть журнал загрузки? [1-нет/2-да]: ",0 +bdev db "Загрузить образ из [1-дискета; 2-C:\menuet.img (FAT32);" db 13,10,186," " db "3-использовать уже загруженный образ]: ",0 probetext db 13,10,13,10,186," Стандартный видеорежим? [1-да, " @@ -90,19 +89,18 @@ probetext db 13,10,13,10,186," ;memokz64 db 13,10,186," RAM 64 Mb",0 ;memokz32 db 13,10,186," RAM 32 Mb",0 ;memokz16 db 13,10,186," RAM 16 Mb",0 -prnotfnd db " pr. - ошибка.",0 -modena db "Ошибка - Требуется поддержка VBE 0x112+.",0 +prnotfnd db "Ошибка - Видеорежим не найден.",0 +;modena db "Ошибка - Требуется поддержка VBE 0x112+.",0 not386 db "Ошибка - Требуется процессор 386+.",0 -btns db 13,10,186," Ошибка - Не могу определить глубину цвета.",0 -fatalsel db 13,10,"Ошибка - Выбранный видеорежим не поддерживается.",0 -badsect db 13,10,186," Ошибка - Дискета повреждена. Попробуйте другую. " - db 0 -memmovefailed db "Fatal - Int 0x15 move failed.",0 +btns db "Ошибка - Не могу определить глубину цвета.",0 +fatalsel db "Ошибка - Выбранный видеорежим не поддерживается.",0 +badsect db 13,10,186," Ошибка - Дискета повреждена. Попробуйте другую.",0 +memmovefailed db 13,10,186," Ошибка - Int 0x15 move failed.",0 okt db " ... OK" linef db 13,10,0 -diskload db 13,10,186," Загрузка дискеты: 00 %",8,8,8,8,0 -backspace db 8,0 -pros db "00",8,8,0 +diskload db "Загрузка дискеты: 00 %",8,8,8,8,0 +pros db "00" +backspace2 db 8,8,0 boot_dev db 0 start_msg db "Нажмите [abcd] для изменения настроек, [Enter] для продолжения загрузки",13,10,0 time_msg db " или подождите " diff --git a/kernel/trunk/core/debug.inc b/kernel/trunk/core/debug.inc new file mode 100644 index 0000000000..37746e5f33 --- /dev/null +++ b/kernel/trunk/core/debug.inc @@ -0,0 +1,344 @@ +; this code uses following additions to system structures: +; in additional app info at 80000..8FFFF: +; AC (dword) 0 or debugger slot +; BC (dword) address of debug event memory +; new process slot state: +; 1 = suspended +; 2 = suspended waiting for event +; new event: 8 (and new possible bitflag for A8 in additional app info) +; diamond, 2006 +sys_debug_services: + cmp eax, 8 + ja @f + jmp dword [sys_debug_services_table+eax*4] +@@: ret +sys_debug_services_table: + dd debug_set_event_data + dd debug_getcontext + dd debug_setcontext + dd debug_detach + dd debug_suspend + dd debug_resume + dd debug_read_process_memory + dd debug_write_process_memory + dd debug_terminate + +debug_set_event_data: +; in: ebx = pointer +; destroys eax + mov eax, [0x3000] + shl eax, 8 + mov [eax+0x80000+0xBC], ebx + ret + +get_debuggee_slot: +; in: ebx=PID +; out: CF=1 if error +; CF=0 and eax=slot*0x20 if ok +; out: interrupts disabled + cli + mov eax, ebx + call pid_to_slot + test eax, eax + jz .ret_bad + shl eax, 5 + push ebx + mov ebx, [0x3000] + cmp [0x80000+eax*8+0xAC], ebx + pop ebx + jnz .ret_bad +; clc ; automatically + ret +.ret_bad: + stc + ret + +debug_detach: +; in: ebx=pid +; destroys eax,ebx + call get_debuggee_slot + jc .ret + and dword [eax*8+0x80000+0xAC], 0 + call do_resume +.ret: + sti + ret + +debug_terminate: +; in: ebx=pid + call get_debuggee_slot + jc debug_detach.ret + mov ebx, eax + shr ebx, 5 + push 2 + pop eax + jmp sys_system + +debug_suspend: +; in: ebx=pid +; destroys eax,ebx + call get_debuggee_slot + jc .ret + mov bl, [0x3000+eax+0xA] ; process state + test bl, bl + jz .1 + cmp bl, 5 + jnz .ret + mov bl, 2 +.2: mov [0x3000+eax+0xA], bl +.ret: + sti + ret +.1: + inc ebx + jmp .2 + +do_resume: + mov bl, [0x3000+eax+0xA] + cmp bl, 1 + jz .1 + cmp bl, 2 + jnz .ret + mov bl, 5 +.2: mov [0x3000+eax+0xA], bl +.ret: ret +.1: dec ebx + jmp .2 + +debug_resume: +; in: ebx=pid +; destroys eax,ebx + call get_debuggee_slot + jc .ret + call do_resume +.ret: sti + ret + +debug_getcontext: +; in: +; ebx=pid +; ecx=sizeof(CONTEXT) +; edx->CONTEXT +; destroys eax,ecx,edx,esi,edi + cmp ecx, 28h + jnz .ret + add edx, std_application_base_address + push ebx + mov ebx, edx + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .ret + imul eax, tss_step/32 + add eax, tss_data + mov edi, edx + cmp [l.cs - tss_sceleton + eax], app_code + jnz .ring0 + lea esi, [l.eip - tss_sceleton + eax] + shr ecx, 2 + rep movsd + jmp .ret +.ring0: +; note that following code assumes that all interrupt/exception handlers +; saves ring-3 context by push ds es, pushad in this order + mov esi, [l.esp0 - tss_sceleton + eax] +; top of ring0 stack: ring3 stack ptr (ss+esp), iret data (cs+eip+eflags), ds, es, pushad + sub esi, 8+12+8+20h + lodsd + mov [edi+24h], eax + lodsd + mov [edi+20h], eax + lodsd + mov [edi+1Ch], eax + lodsd + lodsd + mov [edi+14h], eax + lodsd + mov [edi+10h], eax + lodsd + mov [edi+0Ch], eax + lodsd + mov [edi+8], eax + add esi, 8 + lodsd + mov [edi], eax + lodsd + lodsd + mov [edi+4], eax + lodsd + mov [edi+18h], eax +.ret: + sti + ret + +debug_setcontext: +; in: +; ebx=pid +; ecx=sizeof(CONTEXT) +; edx->CONTEXT +; destroys eax,ecx,edx,esi,edi + cmp ecx, 28h + jnz .ret + add edx, std_application_base_address + push ebx + mov ebx, edx + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .stiret + imul eax, tss_step/32 + add eax, tss_data + mov esi, edx + cmp [l.cs - tss_sceleton + eax], app_code + jnz .ring0 + lea edi, [l.eip - tss_sceleton + eax] + shr ecx, 2 + rep movsd + jmp .stiret +.ring0: + mov edi, [l.esp0 - tss_sceleton + eax] + sub edi, 8+12+8+20h + mov eax, [esi+24h] + stosd + mov eax, [esi+20h] + stosd + mov eax, [esi+1Ch] + stosd + scasd + mov eax, [esi+14h] + stosd + mov eax, [esi+10h] + stosd + mov eax, [esi+0Ch] + stosd + mov eax, [esi+8] + stosd + add edi, 8 + mov eax, [esi] + stosd + scasd + mov eax, [esi+4] + stosd + mov eax, [esi+18h] + stosd +.stiret: + sti +.ret: + ret + +debug_read_process_memory: +; in: +; ebx=pid +; ecx=length +; esi->buffer in debugger +; edx=address in debuggee +; out: [esp+36]=eax=sizeof(read) +; destroys all + add esi, std_application_base_address + push ebx + mov ebx, esi + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .stiret + mov ebx, esi + call read_process_memory +.stiret: + sti +.ret: + ret + +debug_write_process_memory: +; in: +; ebx=pid +; ecx=length +; esi->buffer in debugger +; edx=address in debuggee +; out: [esp+36]=eax=sizeof(write) +; destroys all + add esi, std_application_base_address + push ebx + mov ebx, esi + call check_region + pop ebx + dec eax + jnz .ret + call get_debuggee_slot + jc .stiret + mov ebx, esi + call write_process_memory +.stiret: + sti +.ret: + ret + +debugger_notify: +; in: eax=debugger slot +; ecx=size of debug message +; [esp+4]..[esp+4+ecx]=message +; interrupts must be disabled! +; destroys all general registers +; interrupts remain disabled + mov ebp, eax + shl eax, 8 +.1: + mov edx, [0x80000+eax+0xBC] + test edx, edx + jz .ret +; read buffer header + push ecx + push eax + push eax + mov eax, ebp + mov ebx, esp + mov ecx, 8 + call read_process_memory + cmp eax, ecx + jz @f + add esp, 12 + jmp .ret +@@: + cmp dword [ebx], 0 + jg @f +.2: + pop ecx + pop ecx + pop ecx + sti + call change_task + cli + jmp .1 +@@: + mov ecx, [ebx+8] + add ecx, [ebx+4] + cmp ecx, [ebx] + ja .2 +; advance buffer position + push ecx + mov ecx, 4 + sub ebx, ecx + mov eax, ebp + add edx, ecx + call write_process_memory + pop eax +; write message + mov eax, ebp + add edx, ecx + add edx, [ebx+8] + add ebx, 20 + pop ecx + pop ecx + pop ecx + call write_process_memory +; new debug event + mov eax, ebp + shl eax, 8 + or byte [0x80000+eax+0xA8+1], 1 ; set flag 100h +.ret: + ret diff --git a/kernel/trunk/core/newproce.inc b/kernel/trunk/core/newproce.inc index 83c10c8582..ee1d856415 100644 --- a/kernel/trunk/core/newproce.inc +++ b/kernel/trunk/core/newproce.inc @@ -60,6 +60,7 @@ new_start_application_floppy: ;input: ; eax - pointer to filename ; ebx - parameters to pass +; edx - flags ;result: ; eax - pid of new process ; or 0 if call fails. @@ -231,6 +232,7 @@ new_start_application_fl: ;input: ; eax - pointer to filename ; ebx - parameters to pass +; edx - flags ;result: ; eax - pid of new process ; or 0 if call fails. @@ -546,6 +548,13 @@ new_start_application_fl: mov ebx,[new_process_place] shl ebx,5 mov [0x3000+ebx+0xa],byte 0 ;set process state - running +; set if debuggee + test byte [esp+28], 1 + jz .no_debug + mov [0x3000+ebx+0xa],byte 1 ;set process state - suspended + mov eax,[0x3000] + mov [0x80000+ebx*8+0xac],eax ;set debugger PID - current +.no_debug: mov esi,new_process_running call sys_msg_board_str ;output information about succefull startup @@ -563,6 +572,7 @@ new_sys_threads: ; ecx=thread stack value ;result: ; eax=pid + xor edx,edx ; flags=0 pushad cmp eax,1 @@ -1165,6 +1175,7 @@ new_start_application_hd: ;eax - file name (kernel address) ;ebx - file name length ;ecx - work area (kernel address) +;edx - flags ;ebp - parameters mov [appl_path],edi pushad @@ -1355,3 +1366,5 @@ new_start_application_hd: sti ret end if + + include 'debug.inc' diff --git a/kernel/trunk/core/sched.inc b/kernel/trunk/core/sched.inc index f0cd3e395c..f1b07c30ba 100644 --- a/kernel/trunk/core/sched.inc +++ b/kernel/trunk/core/sched.inc @@ -4,8 +4,7 @@ align 32 irq0: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax @@ -45,6 +44,7 @@ irq0: .waiting_for_termination: .waiting_for_reuse: .waiting_for_event: + .suspended: cmp ebx, [0x3004] jb @f mov edi, 0x3000 @@ -55,6 +55,10 @@ irq0: inc ebx mov al, byte [edi+0xA] + cmp al, 1 + jz .suspended + cmp al, 2 + jz .suspended cmp al, 3 je .waiting_for_termination cmp al, 4 @@ -101,8 +105,7 @@ irq0: inc [context_counter] ;noname & halyavin @@: - pop es ds - popad + restore_ring3_context iret diff --git a/kernel/trunk/core/sys32.inc b/kernel/trunk/core/sys32.inc index c4ddc6af3b..9622a82746 100644 --- a/kernel/trunk/core/sys32.inc +++ b/kernel/trunk/core/sys32.inc @@ -164,6 +164,17 @@ iglobal dd i40 endg +macro save_ring3_context +{ + push ds es + pushad +} +macro restore_ring3_context +{ + popad + pop es ds +} + ; simply return control to interrupted process unknown_interrupt: iret @@ -172,6 +183,7 @@ macro exc_wo_code [num] { forward e#num : + save_ring3_context mov bl, num jmp exc_c } @@ -181,6 +193,7 @@ macro exc_w_code [num] forward e#num : add esp, 4 + save_ring3_context mov bl, num jmp exc_c } @@ -193,6 +206,16 @@ exc_c: mov ds, ax mov es, ax +; test if debugging + cli + mov eax, [0x3000] + shl eax, 8 + mov eax, [0x80000+eax+0xAC] + test eax, eax + jnz .debug + sti +; not debuggee => say error and terminate + add esp, 28h movzx eax, bl mov [error_interrupt], eax call show_error_parameters @@ -202,6 +225,25 @@ exc_c: jmp change_task +.debug: +; we are debugged process, notify debugger and suspend ourself +; eax=debugger PID + movzx ecx, bl + push ecx + mov ecx, [0x3010] + push dword [ecx+4] ; PID of current process + push 12 + pop ecx + push 1 ; 1=exception + call debugger_notify + pop ecx + pop ecx + pop ecx + mov edx, [0x3010] + mov byte [edx+0xA], 1 ; suspended + call change_task + restore_ring3_context + iretd ;;;;;;;;;;;;;;;;;;;;;;; ;; FPU ERROR HANDLER ;; @@ -209,11 +251,8 @@ exc_c: align 4 e7: + save_ring3_context clts - - push eax - push ds es - mov ax, os_data mov ds, ax mov es, ax @@ -232,10 +271,7 @@ e7: frstor [eax+0x10] @@: mov [eax + 0x7f], byte 1 - - pop es ds - pop eax - + restore_ring3_context iret iglobal @@ -320,7 +356,7 @@ macro irqh [num] { forward p_irq#num : - pushad + save_ring3_context mov edi, num jmp irq_c } @@ -328,58 +364,48 @@ macro irqh [num] irqh 2,5,7,8,9,10,11,14,15 irq_c: - push ds es mov ax, os_data mov ds, ax mov es, ax call irqhandler - pop es ds - popad + restore_ring3_context iret p_irq6: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax call fdc_irq call ready_for_next_irq - pop es ds - popad + restore_ring3_context iret p_irq3: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax call check_mouse_data_com2 - pop es ds - popad + restore_ring3_context iret p_irq4: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax call check_mouse_data_com1 - pop es ds - popad + restore_ring3_context iret p_irq12: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax call check_mouse_data_ps2 - pop es ds - popad + restore_ring3_context iret ready_for_next_irq: @@ -396,8 +422,7 @@ ready_for_next_irq_1: ret irqD: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax @@ -410,10 +435,10 @@ irqD: mov al,0x20 out dx,al mov dx,0x20 - out dx,al + out dx,al + + restore_ring3_context - pop es ds - popad iret @@ -650,12 +675,13 @@ terminate: ; terminate application call sys_msg_board_str pop esi +@@: cli cmp [application_table_status],0 je term9 sti call change_task - jmp terminate + jmp @b term9: call set_application_table_status @@ -752,6 +778,23 @@ terminate: ; terminate application rep stosd popa +; debuggee test + pushad + mov edi, esi + shl edi, 5 + mov eax, [0x80000+edi*8+0xAC] + test eax, eax + jz .nodebug + push 8 + pop ecx + push dword [0x3000+edi+0x4] ; PID + push 2 + call debugger_notify + pop ecx + pop ecx +.nodebug: + popad + pusha ; at 0x80000+ mov edi,esi shl edi,8 @@ -863,6 +906,25 @@ terminate: ; terminate application mov edi,esi ; do not run this process slot shl edi, 5 mov [edi+0x300A],byte 9 +; debugger test - terminate all debuggees + mov eax, 2 + mov ecx, 0x80000+2*0x100+0xAC +.xd0: + cmp eax, [0x3004] + ja .xd1 + cmp dword [ecx], esi + jnz @f + and dword [ecx], 0 + pushad + xchg eax, ebx + mov eax, 2 + call sys_system + popad +@@: + inc eax + add ecx, 0x100 + jmp .xd0 +.xd1: ; call systest sti ; .. and life goes on diff --git a/kernel/trunk/core/syscall.inc b/kernel/trunk/core/syscall.inc index 6ef5a695a0..f916e89d6c 100644 --- a/kernel/trunk/core/syscall.inc +++ b/kernel/trunk/core/syscall.inc @@ -8,6 +8,7 @@ align 32 i40: push ds es pushad + cld mov ax,word os_data mov ds,ax @@ -136,9 +137,9 @@ iglobal dd sys_process_def ; 66-Process definitions - keyboard dd sys_window_move ; 67-Window move or resize dd sys_internal_services ; 68-Some internal services + dd sys_debug_services ; 69-Debug times 255 - ( ($-servetable) /4 ) dd undefined_syscall dd sys_end ; -1-end application endg - diff --git a/kernel/trunk/fs/fs.inc b/kernel/trunk/fs/fs.inc index 5197a7da15..3af82834be 100644 --- a/kernel/trunk/fs/fs.inc +++ b/kernel/trunk/fs/fs.inc @@ -318,6 +318,7 @@ endg mov ebx,[ebx+0x10] add ebx,[esp+12] no_fl_start_param: + mov edx,[esp+16] ; flags call start_application_fl @@ -440,6 +441,7 @@ endg add ebx,[esp+12] no_flp_start_param: + mov edx,[esp+16] ; flags call start_application_floppy @@ -778,6 +780,7 @@ choice_necessity_partition_1: mov ebp,[ebp+0x10] add ebp,[esp+12] no_hd_start_param: + mov edx,[esp+16] ; flags call start_application_hd diff --git a/kernel/trunk/gui/event.inc b/kernel/trunk/gui/event.inc index 9b5fd277fd..c883fe7a73 100644 --- a/kernel/trunk/gui/event.inc +++ b/kernel/trunk/gui/event.inc @@ -154,6 +154,18 @@ get_event_for_app: ret no_stack_event: + test byte [edi+1], 1 ; DEBUG + jz no_debug_event + mov eax, [0x3000] + shl eax, 8 + test [eax+0x80000+0xA8+1], byte 1 + jz no_debug_event + and byte [eax+0x80000+0xA8+1], not 1 + popad + mov eax, 9 + ret + no_debug_event: + cmp dword [edi], 0xFFFF jbe no_events diff --git a/kernel/trunk/hid/keyboard.inc b/kernel/trunk/hid/keyboard.inc index f73e46e7ae..7cedad0a2e 100644 --- a/kernel/trunk/hid/keyboard.inc +++ b/kernel/trunk/hid/keyboard.inc @@ -30,8 +30,7 @@ endg align 4 irq1: - pushad - push ds es + save_ring3_context mov ax, os_data mov ds, ax mov es, ax @@ -212,8 +211,7 @@ irq1: mov al,0x20 ; ready for next irq out 0x20,al - pop es ds - popad + restore_ring3_context iret set_lights: diff --git a/kernel/trunk/kernel.asm b/kernel/trunk/kernel.asm index 04b7cd0576..59c05e6152 100644 --- a/kernel/trunk/kernel.asm +++ b/kernel/trunk/kernel.asm @@ -728,12 +728,16 @@ finit ;reset the registers, contents which are still equal RM cmp al,1 jne no_load_vrr_m mov eax,vrr_m + xor ebx,ebx ; no parameters + xor edx,edx ; no flags call start_application_fl cmp eax,2 ; if vrr_m app found (PID=2) je first_app_found no_load_vrr_m: mov eax,firstapp + xor ebx,ebx ; no parameters + xor edx,edx ; no flags call start_application_fl cmp eax,2 ; continue if a process has been loaded @@ -3108,6 +3112,8 @@ checkmisc: cmp [ctrl_alt_del], 1 jne nocpustart mov eax, cpustring + xor ebx,ebx ; no parameters + xor edx,edx ; no flags call start_application_fl mov [ctrl_alt_del], 0 nocpustart: @@ -4570,6 +4576,7 @@ syscall_startapp: ; StartApp add ebx,[edi] noapppar: ; call start_application_fl + xor edx,edx ; compatibility - flags=0 call new_start_application_fl mov [esp+36],eax ret @@ -4604,7 +4611,8 @@ syscall_starthdapp: ; StartHdApp add edi,0x10 add eax,[edi] add ecx,[edi] - mov ebp,0 + xor ebp,ebp + xor edx,edx ; compatibility - flags=0 call start_application_hd mov [esp+36],eax ret