flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > [Solved!] Task switching fails. |
Author |
|
Coty 06 Jan 2011, 16:52
Hello again everyone!
I have been working on a small code demo that swaps between two tasks in 32bit P-mode, sadly I am stuck The goal is to swap between Task A and Task B infinitely using software task switching, I rely on the stack, and IRQ 0, or 'PIT', Now on the bright side, it half works, I can get it to swap to task B from task A, but for some unknown reseon I cannot get it to swap back to task A. I set up for task switching like this: Code: xor ebp, ebp ; EBP == 0x00000000 mov esp, stack1_base ; Declare task 1 stack. ;''''''''''''''''''''''''''''''; ; Put stuff onto the stack for ; ; IRET/IRETD. ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; mov eax, Task1 sti nop pushf ; Push Eflags cli push cs ; Push CS push eax ; Push EIP (well, it will be EIP . pusha ;''''''''''''''''''''''''''''''; ; Swap to stack 0. ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; mov edi, _esp mov esi, edi lodsd xchg eax, esp stosd lodsd xchg eax, ebp stosd ;''''''''''''''''''''''''''''''; ; Goto task 0. .\m/ ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; sti jmp Task0 ; Goto Task 0. Now in theory, it should I should be able to simply swap back to Task1 By switching the Stack and using an iret, this works perfectly! Here is the task switching code: Code: Timer_handle: ; The CPU has pushed the following onto the stack. ; eflags, cs, eip. cli pusha ; Save regs. ;'''''''''''''''''''''''''''''; ; Swap ESP's stack locations. ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; mov esi, _esp ; ESP save spot into ESI. mov edi, esi ; Put it into EDI as well. lodsd ; Load double word xchg eax, esp ; exchange EAX and ESP. stosd ; Save old ESP. ;'''''''''''''''''''''''''''''; ; Swap EBP's location to s1 ; ;,,,,,,,,,,,,,,,,,,,,,,,,,,,,,; lodsd ; Get old EBP xchg eax, ebp ; exchange EAX and EBP. stosd ; Store old EBP. popa ; Restore regs. ; Normaly you would want to use STI, but there is no need ; As IRET pops the eflags reg of the stack, there is a 99% ; chance that interupts are enabled iret _esp: dd stack0_base ; Extra stack pointer save location. dd 0x00000000 ; Extra base pointer save location. stack0_base = 0x00007100 stack1_base = 0x00007200 Now like said It switches me to task1 perfectly, but then it freezes... I have been looking through this code for... a while, and I can't seem to find the problem, it works fine in my head, but sadly I have found that just because it works in my head, does not meen it works in real life Full source attached below. Anyone who can give pointers I will truly be thankful Cheers! ***** I have removed the source code, but you can get the fixed copy on This Post. ***** Last edited by Coty on 06 Jan 2011, 21:08; edited 2 times in total |
|||
06 Jan 2011, 16:52 |
|
Dex4u 06 Jan 2011, 18:11
Do you send a end of irq
eg: Code: mov al,0x20 out 0xa0,al out 0x20,al At the end of your Timer_handle ?. |
|||
06 Jan 2011, 18:11 |
|
Dex4u 06 Jan 2011, 20:29
Thats some cool code, I did notice this
Code: ;=============================================================================; ; Task A and B go here... ; ;=============================================================================; Task0: Mov ah, 0 ; INT 0x70, AH = 0, Print Char Mov al, 'A' ; Print an A Int 0x70 ; Print hlt ; print only 1 char each time the task ; is returned to... Jmp Task0 end_0: Task1: Mov ah, 0 ; INT 0x70, AH = 0, Print Char Mov al, 'B' ; Print an B Int 0x70 ; Print hlt ; print only 1 char each time the task ; is returned to... Jmp Task0 ;SHOULD THIS NOT BE Task1 ? end_1: Last edited by Dex4u on 06 Jan 2011, 21:13; edited 2 times in total |
|||
06 Jan 2011, 20:29 |
|
Coty 06 Jan 2011, 21:05
Dex4u wrote:
Well, I guess that what I get when I just copy/paste task A Dex4u wrote: I only know where to look, because i have made the same mists as you In that case someday maby I will know were to look to I give you a million thanks!, but If I typed them all it would probably be considered a waste of bandwidth I have attached below a version with the problems fixed and a memory map for future reference/if anyone is interested. Cheers!
|
|||||||||||
06 Jan 2011, 21:05 |
|
Dex4u 06 Jan 2011, 21:09
Coty wrote:
Cool thanks. |
|||
06 Jan 2011, 21:09 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.