; (c) tkraj 2000 ; .286p ; ; PLACE MACRO dest_seg,src_seg,length mov ax,src_seg mov ds,ax mov ax,dest_seg mov es,ax mov cx,length xor si,si xor di,di rep movsb ENDM ; ; pjmp MACRO selector,offset db 0eah dw offset dw selector ENDM ; ; pcall MACRO selector,offset db 9ah dw offset dw selector ENDM ; ; seg_desc struc limit15_0 dw ? base15_0 dw ? base23_16 db ? acc_rights db ? reserved1 dw 0 seg_desc ends ; ; ; *** GDT AT ADDRESS 051000h *** ; GDT segment ; Selector: null_desc seg_desc <0,0,0,0,0> ; 00h vga_desc seg_desc <0ffffh,8000h,0bh,10010010b,>; 08h disp_desc seg_desc <03ffh,2000h,05h,10011000b,>; 10h stack1_desc seg_desc <0bffh,3000h,05h,10010110b,>; 18h ; stack size = 1 kB => addr_high = 53fffh and addr_low = 53c00h ; limit = 0bffh (all offsets must be > limit) ; init_value of SP = 1000h data1_desc seg_desc <03ffh,4000h,05h,10010010b,>; 20h task1_desc seg_desc <03ffh,5000h,05h,10011000b,>; 28h end_gdt: GDT ends ; ; ; *** DISP AT ADDRESS 052000h *** ; DISP segment assume cs:DISP,ds:DATA1 DISPVGA proc far ; offset of text in SI ; char CR ends text start2: mov di,line ; position on screen again2: mov al,[si] cmp al,0dh ; test on CR je test21 mov es:[di],al add di,2 ; skip attribute byte inc si jmp again2 test21: add line,160 ; new line ret end2: DISPVGA endp DISP ends ; ; ; *** DATA1 AT ADDRESS 054000h *** ; ; DATA1 segment line dw 0 clear db " ",0dh text1 db "Privileged mode initialized.",0dh text2 db "Task1 started.",0dh text3 db "Task1 finished.",0dh text4 db "Privileged mode finished, return into real mode.",0dh end4 db ? DATA1 ends ; ; ; *** TASK1 AT ADDRESS 055000h *** ; TASK1 segment assume cs:TASK1 start5: cli mov ax,18h mov ss,ax mov sp,1000h ; init of the SP mov ax,08h mov es,ax ; init of the vga segment mov ax,20h mov ds,ax ; init of the data1 segment mov cx,24 again51: mov si,offset clear pcall 10h,0h loop again51 ; clear of the display mov line,320 ; cursor at line 2 mov si,offset text1 pcall 10h,0h mov si,offset text2 pcall 10h,0h mov si,offset text3 pcall 10h,0h mov si,offset text4 pcall 10h,0h mov al,0fh out 70h,al jmp $+2 ; delay mov al,0ah out 71h,al ; flag of return from protected ; mode into CMOS mov al,0feh out 64h,al ; pulse reset, cool start hlt ; stop the processor end5: TASK1 ends ; ; ; ; *** INITIALIZATION OF PRIVILEGED MODE *** ; ini_dat segment gdt_desc seg_desc <03ffh,1000h,05h,,> privil_mode dw 0fff1h ini_dat ends ; ; ini_cod segment assume cs:ini_cod,ds:ini_dat start: PLACE 5100h,GDT,(end_gdt-null_desc) PLACE 5200h,DISP,(end2-start2) PLACE 5400h,DATA1,(end4-line) PLACE 5500h,TASK1,(end5-start5) xor ax,ax mov es,ax ; base for return addr mov bx,0467h mov word ptr es:[bx],OFFSET return mov word ptr es:[bx+2],SEG return cli mov ax,ini_dat mov ds,ax lgdt gdt_desc lmsw privil_mode ; ; *** PRIVILEGED MODE *** ; jmp $+2 ; empty queue pjmp 0028H,0000H ; start of TASK1 return: mov ah,4ch int 21h ini_cod ends ; ; end start