OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 10:14 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 2:59 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
I was told that the cpu will push the following onto stack for interrupt handling the following
in that order

Code:
u32int eip, cs, eflags, useresp,
ss

but when I print out those values one by one

I found that ss in not 0x10, it is actually similar to useresp, which is a stack value,,

what is going on???


Last edited by ITchimp on Fri Jun 05, 2020 3:27 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 3:04 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
IIRC, those two are user mode values which means they will contain trash in kernel mode.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 3:24 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
how does then iret deal with them? what should I do? what is the recourse?

also there is eflags that is also on the stack....


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 3:36 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Simple - there's something wrong with your print routine. It looks like you are starting at the wrong position on the stack. Presumably you are looking at an interrupt whilst running in user mode?

Run your code under a debugger, set a break point in the interrupt handler, and look at the stack.


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 4:25 am 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
I am running everything in bochs.... don't know how to run the debugging mode...
but I am however aware of xchg %bx, %bx hack, it was not always usefull. but I am trying...


how to run hte kernel in debugger like what you said?


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 4:44 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
https://wiki.osdev.org/Kernel_Debugging

Learn how to use a debugger - it will serve you well when you get to the difficult stuff.


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 8:26 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 15, 2018 2:27 pm
Posts: 201
This thread subject sounds (reads?) just as these shady scam ads :lol:
Like 'You won't believe…' or 'Doctors hate this guy for…' or 'Tried out new IDT set up but this happened!!!'


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 11:56 am 
Offline
Member
Member

Joined: Wed Aug 30, 2017 8:24 am
Posts: 1604
In 32-bit mode, SS and ESP are only pushed to the stack if a change of privilege level occurred. So if CS indicates ring 0 then ESP and SS are invalid values.

_________________
Carpe diem!


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 5:51 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
I think this forum needs a healthy dose of energy injection... :mrgreen:


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 6:42 pm 
Offline
Member
Member

Joined: Sat Aug 18, 2018 8:44 pm
Posts: 127
first I bow to all the OS gods and immortals!!!

I have yet another problem that I just discovered...

context, I am running in kernel mode so there is no priviledge change...

the problem I have is that the code returning from ISR corrupts the stack

the magic_break option is enabled so "xchg %bs, %bs;" will generate a break point

the ISR common stub is the following, it is as standard as it gets

first I bow to all the OS gods and immortals!!!

I have yet another problem that I just discovered...

context, I am running in kernel mode so there is no priviledge change...

the problem I have is that the code returning from ISR


Code:
isr_common_stub:

pusha
mov %ds, %ax
push %eax
mov $10, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
mov %ax, %gs
call isr_handler
pop %ebx
mov %bx, %ds
mov %bx, %es
mov %bx, %fs
mov %ax, %gs
popa
add 8, %esp
sti
iret


on bochs debugging prompt, I notice that

Code:
add 8, %esp
produces the following assembly routine (it is a bit weird)

Code:
add esp, dword ptr ds:0x8


but the test code of the tutorial I am following, which behaves correctly

produces a slight different assembly:

Code:
add esp, 0x00000008


so the net result is that the test code behaves correct. my own code corrupts the stack... I am wondering why the same isr_common_stub generates different code?


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 7:25 pm 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
You already asked that question and got the answer.


Top
 Profile  
 
 Post subject: Re: tried out new idt set up but this happened!!!
PostPosted: Fri Jun 05, 2020 11:37 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
Learn the particular.assembler syntax that you are using.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot], MichaelPetch and 119 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group