Code: Select all
void far_jmp(unsigned int selector) {
__asm__ __volatile__ ("ljmp *%0": :"m" ((selector)) : "memory");
}
Code: Select all
#define far_jmp(selector) __asm__ __volatile__ ("ljmp *%0": :"m" ((selector)) : "memory");
Code: Select all
void far_jmp(unsigned int selector) {
__asm__ __volatile__ ("ljmp *%0": :"m" ((selector)) : "memory");
}
Code: Select all
#define far_jmp(selector) __asm__ __volatile__ ("ljmp *%0": :"m" ((selector)) : "memory");
Hi,Brendan wrote:Hi,
Just a quick note...
This won't work, because the selector for a far jump comes after the offset (not before). You'd actually need something like:pcmattman wrote:Code: Select all
void far_jmp(unsigned int selector) { asm ("ljmp %0": :"m" (selector)); }
I'm not sure about inline GAS syntax - something like this might work:Code: Select all
jmp far [address_of_selector_on_stack - 4]
Code: Select all
void far_jmp(unsigned int selector) { asm ("ljmp -4(%0)": :"m" (selector)); }
Cheers,
Brendan
Code: Select all
asm( "ljmp %0,$0" : : "m" (selector ) );
Code: Select all
ljmp [seg],[offset]
Code: Select all
struct __attribute__ ((__packed__)) tss_t
{
word link, __blh;
dword esp0;
word ss0, __ss0h;
dword esp1;
word ss1, __ss1h;
dword esp2;
word ss2, __ss2h;
dword cr3;
dword eip;
dword eflags;
dword eax, ecx, edx, ebx;
dword esp, ebp, esi, edi;
word es, __esh;
word cs, __csh;
word ss, __ssh;
word ds, __dsh;
word fs, __fsh;
word gs, __gsh;
word ldt, __ldth;
word trace, bitmap;
};
That is an "immediate far jump", not an "indirect far jump".pcmattman wrote:A far jump syntax is (not back-to-front like everything else in AT&T syntax)Code: Select all
ljmp [seg],[offset]
Code: Select all
jmp far seg:offset
Code: Select all
jmp $seg,$offset
Code: Select all
jmp far [address_of_offset]
jmp far [eax]
Code: Select all
ljmp *address_of_offset
ljmp *(%eax)
Code: Select all
jmp far [address_of_selector - 4]
jmp far [eax - 4]
Code: Select all
ljmp *address_of_selector-4
ljmp *-4(%eax)
Code: Select all
__asm__ __volatile__ ("ljmp *-4%0\n" : :"m"(selector));
Code: Select all
ljmp *-48(%ebp)-4
Code: Select all
ljmp *4(%ebp)
Code: Select all
void far_jmp(unsigned int volatile selector) {
__asm__ __volatile__ ("ljmp *%0\n" : :"r"((void *)&selector - 4));
}
Code: Select all
.globl far_jmp
.type far_jmp, @function
far_jmp:
pushl %ebp
movl %esp, %ebp
leal 4(%ebp), %eax
#APP
ljmp *%eax
#NO_APP
popl %ebp
ret
.size far_jmp, .-far_jmp
Code: Select all
.globl far_jmp
.type far_jmp, @function
far_jmp:
#APP
ljmp *%esp
#NO_APP
ret
Code: Select all
void far_jmp(unsigned int selector) {
__asm__ __volatile__ ("ljmp *%0\n" : :"r"((void *)&selector - 4) : "memory");
}
Code: Select all
0x00104fd0: 0x00000020 0x00000100 0x00104fe8 0x001004de
I really didn't get it,what should i do to correct that ?The CS near the end of the TSS must have been correct though...
Code: Select all
void far_jmp(unsigned int selector)
{
__asm__ __volatile__ ("ljmp *%0\n" : :"r"((void *)&selector -4) : "memory");
}
If CS is already correct and it executes zeros after the task switch, then the value in the TSS's EIP field is wrong or something else is wrong (linker script, code that relocates the new task, etc)...abuashraf wrote:I really didn't get it,what should i do to correct that ?The CS near the end of the TSS must have been correct though...
Doh - just when I thought I'd got it right!abuashraf wrote:Unfortunately this codewasn't acceptable by GCC it gave me an error.Code: Select all
void far_jmp(unsigned int selector) { __asm__ __volatile__ ("ljmp *%0\n" : :"r"((void *)&selector -4) : "memory"); }
Code: Select all
void far_jmp(unsigned int selector)
{
__asm__ __volatile__ ("ljmp *(%0)\n" : :"r"((void *)&selector -4) : "memory");
}
Code: Select all
jmp base:offset
Code: Select all
jmp ax:.flush
Code: Select all
jmp word [sel]:.flush
Code: Select all
void far_jmp(unsigned int selector)
{
__asm__ __volatile__ ("ljmp *(%0)\n" : :"r"((void *)&selector -4) : "memory");
}
80x86 CPUs don't support what you're looking for. To reload CS and EIP at the same time you'd use an indirect jump:axelo wrote:Often base is hardcoded to 0x08, but I was wondering if it is possible to let the base be in a memory location or in a reg. I tried some combinations but nasm complains of invalid combination.
Code: Select all
mov dword [some_address], the_offset
mov word [some_address + 4], the_selector
jmp [some_address]
Code: Select all
push dword the_selector
push dword the_offset
retf
Congratulationsabuashraf wrote:Finally it's working ....unbelievable
you were amazing Brendan thank you,thank you frank so much...
It's mostly the same as it was before you started adding multitasking - the main difference is that you need to put something in each TSS's CR3 field. For now, just use the same page directory for all tasks (but sooner or later you'll probably want to create new page directories for new tasks so they run in their own address space).abuashraf wrote:I already implemented paging in my kernel but when I was working
on multitasking I disabled paging so not to get page fault exception.
Now before my multitasking gets more complicated,(till now it's simple)
I want to enable paging with multitasking how can I do that?