multitasking
Posted: Fri Feb 15, 2008 6:27 am
Hi i implemented multitasking in my baby kernel, in this modes:
SJF, FCFS, RR (round-robin)
SJF, FCFS, RR (round-robin)
Code: Select all
;IN: edi=@register_set
vga.set_registers:
push eax
push ecx
push edx
push edi
;MISC
mov dx, vga.reg.misc_write
mov al, [edi]
out dx, al
inc edi
;sequencer
xor ecx, ecx
.loop_seq:
mov dx, vga.reg.seq_index
mov eax, ecx
out dx, al
mov dx, vga.reg.seq_data
mov al, [edi]
out dx, al
inc edi
inc ecx
cmp ecx, 5
jne .loop_seq
;unlock crtc registers
mov dx, vga.reg.crtc_index
mov al, 3
out dx, al
mov dx, vga.reg.crtc_data
in al, dx
or al, 0x80 ;set ? bit
out dx, al
mov dx, vga.reg.crtc_index
mov al, 11
out dx, al
mov dx, vga.reg.crtc_data
in al, dx
and al, 0x7F ;del ? bit
out dx, al
;???make sure they remain unlocked???
or byte[edi+ 3],0x80
and byte[edi+11],0x7F
;write crtc registers
xor ecx, ecx
.loop_crtc:
mov dx, vga.reg.crtc_index
mov eax, ecx
out dx, al
mov dx, vga.reg.crtc_data
mov al, [edi]
out dx, al
inc edi
inc ecx
cmp ecx, 25
jne .loop_crtc
;write gc (graphic controller) registers
xor ecx, ecx
.loop_gc:
mov dx, vga.reg.gc_index
mov eax, ecx
out dx, al
mov dx, vga.reg.gc_data
mov al, [edi]
out dx, al
inc edi
inc ecx
cmp ecx, 9
jne .loop_gc
;write ac (attribute controller) registers
xor ecx, ecx
.loop_ac:
;?
mov dx, vga.reg.instat_read
in al, dx
;?
mov dx, vga.reg.ac_index
mov eax, ecx
out dx, al
mov dx, vga.reg.ac_data_write
mov al, [edi]
out dx, al
inc edi
inc ecx
cmp ecx, 21
jne .loop_ac
;/* lock 16-color palette and unblank display */
; (void)inportb(VGA_INSTAT_READ);
; outportb(VGA_AC_INDEX, 0x20);
;???lock 16 color palette???
mov dx, vga.reg.instat_read
in al, dx
mov dx, vga.reg.ac_index
mov al, 0x20
out dx, al
pop edi
pop edx
pop ecx
pop eax
ret
Code: Select all
vga.mode.text_80x25: ;this is the standard mode!
;MISC
db 0x67
;SEQ
db 0x03, 0x00, 0x03, 0x00, 0x02
;CRTC
db 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F
db 0x00, 0x4F, 0x0D, 0x0E, 0x00, 0x00, 0x00, 0x50
db 0x9C, 0x0E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3
db 0xFF
;GC
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x00
db 0xFF
;AC
db 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07
db 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
db 0x0C, 0x00, 0x0F, 0x08, 0x00
vga.mode.text_80x50:
;MISC
db 0x67
;SEQ
db 0x03, 0x00, 0x03, 0x00, 0x02
;CRTC
db 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81, 0xBF, 0x1F
db 0x00, 0x47, 0x06, 0x07, 0x00, 0x00, 0x01, 0x40
db 0x9C, 0x8E, 0x8F, 0x28, 0x1F, 0x96, 0xB9, 0xA3
db 0xFF
;GC
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0E, 0x00
db 0xFF
;AC
db 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07
db 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
db 0x0C, 0x00, 0x0F, 0x08, 0x00
vga.mode.graphic_320x200x256:
;MISC
db 0x63
;SEQ
db 0x03, 0x01, 0x0F, 0x00, 0x0E
;CRTC
db 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0xBF, 0x1F
db 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0x9C, 0x0E, 0x8F, 0x28, 0x40, 0x96, 0xB9, 0xA3
db 0xFF
;GC
db 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F
db 0xFF
;AC
db 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07
db 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
db 0x41, 0x00, 0x0F, 0x00, 0x00
vga.mode.graphic_640x480x16:
;MISC
db 0xE3
;SEQ
db 0x03, 0x01, 0x08, 0x00, 0x06
;CRTC
db 0x5F, 0x4F, 0x50, 0x82, 0x54, 0x80, 0x0B, 0x3E
db 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
db 0xEA, 0x0C, 0xDF, 0x28, 0x00, 0xE7, 0x04, 0xE3
db 0xFF
;GC
db 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x05, 0x0F
db 0xFF
;AC
db 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x14, 0x07
db 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F
db 0x01, 0x00, 0x0F, 0x00, 0x00
Code: Select all
mov edi, vga.mode.graphic_320x200x256
call vga.set_registers
Yes, this was the one I "stole" it from. :3
Code: Select all
byte peekb(void *S, short O)
{
byte *mm = (byte *)S;
return mm[O];
}
void pokeb(void *S, short O, byte V)
{
byte *mm = (byte *)S;
mm[O] = V;
}
void pokew(void *S, short O, word V)
{
word *mm = (word *)S;
mm[O] = V;
}
void _vmemwr(void *DS,short DO, const void *S, int N)
{
const char *sp = (const char *)S;
char *dpn = (char *)DS;
char *dp = dpn[DO];
for(; N != 0; N--) *dp++ = *sp++;
}
Code: Select all
byte peekb(void *S, short O)
{
byte *mm = (byte *)S;
return mm[O];
}
void pokeb(void *S, short O, byte V)
{
byte *mm = (byte *)S;
mm[O] = V;
}
void pokew(void *S, short O, word V)
{
word *mm = (word *)S;
mm[O] = V;
}
void _vmemwr(void *DS,short DO, const void *S, int N)
{
const char *sp = (const char *)S;
char *dpn = (char *)DS;
char *dp = dpn[DO];
for(; N != 0; N--) *dp++ = *sp++;
}
Code: Select all
void _farpokeb(unsigned short selector,
unsigned long offset,
unsigned char value)
{
__asm__ __volatile__ ("movw %w0,%%fs\n"
" .byte 0x64 \n"
" movb %b1,(%k2)"
:
: "rm" (selector), "qi" (value), "r" (offset));
}
unsigned char
_farpeekb(unsigned short selector,
unsigned long offset)
{
unsigned char result;
__asm__ __volatile__ ("movw %w1,%%fs \n"
" .byte 0x64 \n"
" movb (%k2),%b0"
: "=q" (result)
: "rm" (selector), "r" (offset));
return result;
}