Hi people.


Here Im stuck again :), I normally are a person that dont ask, then you will perdon me if I dont know how to ask questions :) or paste to much code like anterior one post :), but I try to go to the poin.

I have no time this days for rewrite the programm and see if it change something or I repeat the same error.

this is the error I obtain from bochs...


00000652162p >>PANIC<< fetch_raw_descriptor: LDTR.valid=0
00000652162i Last time is 1117073601
00000652162i protected mode
00000652162i CS.d_b = 16 bit
00000652162i SS.d_b = 16 bit
00000652162i | EAX=00000020  EBX=00000030  ECX=00150003  EDX=00000d0c
00000652162i | ESP=0000f7ce  EBP=00000000  ESI=00000002  EDI=000000ac
00000652162i | IOPL=0 NV UP DI PL NZ NA PO NC
00000652162i | SEG selector    base    limit G D
00000652162i | SEG sltr(index|ti|rpl)    base    limit G D
00000652162i |  DS:0010( 0002| 0|  0) 00010000 0000ffff 0 0
00000652162i |  ES:0010( 0002| 0|  0) 00010000 0000ffff 0 0
00000652162i |  FS:0020( 0004| 0|  0) 000b8000 0000ffff 0 0
00000652162i |  GS:0020( 0004| 0|  0) 000b8000 0000ffff 0 0
00000652162i |  SS:0018( 0003| 0|  0) 00010000 0000ffff 0 0
00000652162i |  CS:0008( 0001| 0|  0) 00010000 0000ffff 0 0
00000652162i | EIP=00000fe2 (00000fe0)
00000652162i | CR0=0x60000011 CR1=0x00000000 CR2=0x00000000
00000652162i | CR3=0x00000000 CR4=0x00000000
00000652162i[    ] restoring default signal behavior
00000652162i quit_sim called with exit code 1



From this value "EIP=00000fe2 (00000fe0)" I have taked fe0 = 4064 I hae a macro for print the "offset" about a line and here is that line: [4064] JMP FAR

The scheduler look like this:

scheduler:
; ret ; uncomment this for "manual test"
mov si,
inc si
cmp si, MAX_TASK
jb .cont
xor si, si
.cont
mov , si
shl si, 1
mov bx,
OFFSETHERE JMP FAR ; THIS IS THE MACRO FOR PRINT THE OFFSET
jmp far
ret


Things that are related to the task...


gdt_label: times ((5+MAX_TASK)*DESCR_SEG_size) db 0
gdtr_label: times DESCR_GDTR_size db 0

taskList: times MAX_TASK*DESCR_TSS_size db 0
total_task dw MAX_TASK
cur_task dw 0
task_sel times MAX_TASK dw 0


%define STACK_SIZE 1024
task_stack times STACK_SIZE db 0



How I setup pmode....


setup_pmode:
    ; /* disable interrupts so that IRQs don't cause exceptions */
cli
; /* disable NMIs as well */
in al, 0x70
or al, 0x80
out 0x70, al

call setup_GDT
call setup_IDT

; /* save IRQ masks */
; old_IRQ_mask[0] = inportb (PORT_8259M+1);
in al, PORT_8259M+1
mov , al
; old_IRQ_mask[1] = inportb (PORT_8259S+1);
in al, PORT_8259S+1
mov , al

; /* setup PIC */
; setup_PIC (0x20, 0x28);
invk setup_PIC, byte 0x20, byte 0x28
; /* set new IRQ masks */
; outportb (PORT_8259M+1, 0xFC);      /* enable timer and keyboard (master) */
mov al, 0xfc
out PORT_8259M+1, al
; outportb (PORT_8259S+1, 0xFF);      /* disable all (slave) */
mov al, 0xff
out PORT_8259S+1, al

; /* saving real mode segment addresses */
mov ax, cx
mov , ax
mov ax, ds
mov , ax
mov ax, ss
mov , ax
; mov ax, sp
; mov , ax
; /* WOW!!! This switches us to PMode just setting up CR0.PM bit to 1 */
invk read_cr0 ; ; return dx:ax
or ax, 1
invk write_cr0, eax

; /* loading segment registers with PMode selectors */
invk update_cs, 0x8
mov ax, 0x10
mov ds, ax
mov es, ax
mov ax, 0x18
mov ss, ax ; I was having problems here... because at startup I put 0x9000 in SS in real mode...

; /* if we don't load fs and gs with valid selectors, task switching may fail. */
invk load_fs, 0x10
invk load_gs, 0x10

; /* due to the same reason, let's clear ldtr */
invk load_ldt, gdt_label

mov di, 80*1
mov si, pm_OK
invk write_msg

xor cx, cx
mov bx, taskList
xor edx, edx
mov dx, task_stack
.again:
mov eax, 0
mov , ax
mov word, DESCR_TSS_size

or cx, cx
jz .check
mov , eax
mov , eax
mov , eax

            mov eax, ds
mov , eax
mov , eax
mov , eax

mov eax, cs
mov , eax

mov dword, 0x202
mov , edx
add edx, STACK_SIZE
.check
add bx, DESCR_TSS_size
inc cx
cmp cx, 3
jb .again
mov dword, task1
mov dword, task2

; /* load the TR register */
OFFSETHERE MOV AX
mov ax,
invk load_ltr, ax
sti
ret


The task and the "start"


task1:
.again
mov al,
mov , al
mov di, 80 * 8
mov si, mt1
invk write_msg
jmp .again
ret
task2:
.again
mov al,
mov , al
mov di, 80 * 9
mov si, mt2
invk write_msg
jmp .again
ret


start2:
....

call setup_pmode

; db 0xea, 0,0, 0x28, 0 ; jump_protected: JUMP to busy 386 TSS unsupported.
; jmp 0x30:0 ; it is called ok :)
; jmp 0x38:0 ; called ok.

.again
mov al,
mov , al
mov di, 80 * 6
mov si, mt0
push ax
invk write_msg
pop ax
cmp al, 0x81
je .end
jmp .again
.end

; jmp 0x30:0 ; called OK
; jmp 0x38:0 ; called OK

invk shut_down

ret


If you need other code... say me.

OK, I have tested my "tasks" independent without the scheduler (see the diferent jumps, and uncomment the ret in the scheduler) for enter to manual test... and aparently, I can jump one time to them to task 1 and 2 And they print the msg and read the scancode and replace it on the screen, then aparently they work ok,one by one. but dont know what happend when I try to schedule them... I dont know, if you see bochs breaks with "EBX=00000030" and "ESI=00000002" with ip pointing (If Im not wrong ) to jmp far if you see task sel, it will contain task_sel dw 0x28, 0x30, 0x38 (30 and 38 are task1 and 2) I assume that 0x28 is the actual code running (or main task? and not need be filled), like I see, was the first time the scheduler was entering, it take the actual task (initializated to zero), add 1 to si (first task no zero task) and mul by 2, then I move what is inside task_sel (a selector in the GDT) and then SI=2 bx=0x30 (task 1).

Some one have a idea of what probably Im doing wrong?
Posted on 2005-05-25 21:39:31 by rea
OK, after the post, I have done some test.... in the last part, where I do my "manual test", I use the next


; db 0xea, 0,0, 0x28, 0 ; jump_protected: JUMP to busy 386 TSS unsupported.
; jmp 0x30:0 ; it is called ok :)
; jmp 0x38:0 ; called ok.


I have added what Im doing inside the scheduler (the function that aparently cause the fault...)


1
mov bx, 0x30
jmp far
;  jmp 0x30:0 ; it is called ok :)

2
mov bx, 0x38
jmp far
; jmp 0x38:0 ; it is called ok :)



Aparently 1 cause the thing about bochs to stop (the exact same thing) ">>PANIC<< fetch_raw_descriptor: LDTR.valid=0", and with 2 cause a get out of PM but the exception handler dosent print a message.., tought If I initialize the cur_tas to 1, then task2 will be called by the scheduler, and there the exception handler print a message (dont know why manually tought it print out of PM, dosent print exception)


Out Of PM
      exception Number 000D        At address 100C:00080002 ERROR EFE8



Im thinking now that jump far is not exaclty jmp 0x30:00 or so....

??????
Posted on 2005-05-25 22:00:29 by rea
Ok, I have changed a little my code for check the thing about the far jump with and replace with a direct jump xxx:x, and aparently it work ok (for very short time...).

scheduler:

scheduler:
mov si,
inc si
cmp si, MAX_TASK
jb .cont
xor si, si
.cont
mov , si
jnz .nextcase1
jmp 0x28:0
.nextcase1
cmp si, 1
jnz .nextcase2
jmp 0x30:0
.nextcase2
jmp 0x38:0
ret

tasks

mt0 db "  Task 0", 0
mt1 db "  Task 1", 0
mt2 db "  Task 2", 0
;couters
ct1 db "A"
ct2 db "A"
ct0 db "A"

task1:
.again
mov al,
inc al
mov , al
mov , al
mov di, 80 * 8
mov si, mt1
invk write_msg
jmp .again
ret
task2:
.again
mov al, ;mov al,
inc al
mov , al
mov , al ; mov , al
mov di, 80 * 9
mov si, mt2
invk write_msg
jmp .again
ret


start2:
....
call setup_pmode
.again
mov al,
inc al
mov , al
mov , al
mov di, 80 * 6
mov si, mt0
push ax
invk write_msg
pop ax
cmp al, 0x81
je .end
jmp .again
.end
invk shut_down
ret


The error that bochs give is:

00000653811p >>PANIC<< task_switch: CS NULL
00000653811i Last time is 1117123995
00000653811i protected mode
00000653811i CS.d_b = 16 bit
00000653811i SS.d_b = 16 bit
00000653811i | EAX=00000020  EBX=00000022  ECX=00000000  EDX=00000000
00000653811i | ESP=000008dc  EBP=00000000  ESI=101b0000  EDI=028601aa
00000653811i | IOPL=0 NV UP DI PL ZR NA PE NC
00000653811i | SEG selector    base    limit G D
00000653811i | SEG sltr(index|ti|rpl)    base    limit G D
00000653811i |  DS:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i |  ES:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i |  FS:0000( 0000| 0|  0) 000b8000 0000ffff 0 0
00000653811i |  GS:0000( 0000| 0|  0) 000b8000 0000ffff 0 0
00000653811i |  SS:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i |  CS:0000( 0000| 0|  0) 00010000 0000ffff 0 0
00000653811i | EIP=00000fe1 (00000fe1)
00000653811i | CR0=0x60000019 CR1=0x00000000 CR2=0x00000000
00000653811i | CR3=0x00000000 CR4=0x00000000
00000653811i[    ] restoring default signal behavior
00000653811i quit_sim called with exit code 1


But there is printed the following in the screen.

Hi. Welcome to the 5th PMode tutorial! Protected mode is OK
We are in Protected Mode

F Task 0
I Task 1                                            I task2



If all the c(ounter)t(ask)N are initializate to "A", task 0 as incremented 6 times and task1 and task2 8 times. But if there exist switch in that moment, what change the execution for cause that exception???
Posted on 2005-05-26 11:14:42 by rea