Switching to task

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Jane1991c
Posts: 22
Joined: Mon Oct 21, 2013 3:48 pm

Switching to task

Post by Jane1991c »

Hey, I have succesfully loaded task0 with ltr instruction.
I have also prepared task1, here are parts of code:

Code: Select all

...

mov word [tss_1+4ch], 8 ; cs
mov word [tss_1+20h], proc_1 ;eip
mov word [tss_1+50h], 24 ;ss
mov word [tss_1+38h], 128 ;esp
mov word [tss_1+54h], 16
mov word [tss_1+48h], 32

cli
;enter PM Mode here


mov ax, 48
ltr ax

call dword 0x00000038 ; selector = 56 for tss1

loopme:
jmp loopme

proc1:
mov ax, 1h
iret

my gdt:
1. null
2. program, selector = 8
3. data, selector = 16
4. stack, sel = 24
5. screen, sel=32
6.my extra seg, sel=40
7. tss0, sel=48
8. tss1, sel=56

error:
00015175139e[CPU0 ] branch_near32: offset outside of CS limits
00015175139e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x0d)
00015175139e[CPU0 ] interrupt(): gate descriptor is not valid sys seg (vector=0x08)
What is wrong ? It seems it didnt use my selector 56. Why ?
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Switching to task

Post by Nable »

> word > eip
> word > esp
Can you see any inconsistency here? So, upper words of 32-bit fields contain garbage.
There are also too many "magic" constants in this piece of code, so my static analyzer refused to check it further.
Jane1991c
Posts: 22
Joined: Mon Oct 21, 2013 3:48 pm

Re: Switching to task

Post by Jane1991c »

Nable wrote:> word > eip
> word > esp
Can you see any inconsistency here? So, upper words of 32-bit fields contain garbage.
There are also too many "magic" constants in this piece of code, so my static analyzer refused to check it further.
Dunno if i understood you properly, but here is version that fills whole value. Same error returned "branch_near32: offset outside of CS limits"


Code: Select all

...

; init tss_1
mov word [tss_1+4ch], 0x00000008 ; cs

mov word [tss_1+20h], 0x00000000
mov word [tss_1+20h], zadanie_1 ;eip

mov word [tss_1+50h], 0x00000018 ;24 ;ss
mov word [tss_1+38h], 0x00000080 ;128 ;esp
mov word [tss_1+54h], 0x00000010 ;16
mov word [tss_1+48h], 0x00000020 ;32

cli
;enter PM Mode here


mov ax, 48
ltr ax

call dword 0x00000038 ; selector = 56 for tss1

loopme:
jmp loopme

proc1:
mov ax, 1h
iret

tss_0	times 104 db 0
tss_1	times 104 db 0
I have noticed while debugging such instruction in bochs:
call .-32864 (0x00000038) ; that is my call dword 0x00000038

Seems like it dont understand that i want to run new task than normal procedure, whats wrong ?

What is wrong ?

PROBLEM SOLVED, REASON: WRONG EIP WAS SET BECOUSE OF ORG DECLARATION IN FILE, THANKS FOR HELP!
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Switching to task

Post by Combuster »

here is (the) version that fills (the) whole value
mov word [tss_1+48h], 0x00000020 ;32
WRONG.

Start with proving mathematically that "0000000000000000" is a different number than "0" - and as much as that is an impossibility, so qualifies your change as nonsense. "mov word" explicitly says to do a 16-bit transfer - not whatever number you put there. On a real machine you are likely going to get garbage values for the remaining 16 bits.



Also, you didn't read the forum rules properly because you used colours. That also means that you missed all the requirements and useful tips on problem solving as well. Please go read them.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply