OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Jan 18, 2019 6:03 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: I cannot get GDT working
PostPosted: Fri Apr 13, 2018 10:22 am 
Offline

Joined: Fri Apr 13, 2018 10:18 am
Posts: 23
I am writing an operating system in C based on OSDev's Meaty Skeleton example, and I want to specify my own GDT instead of GRUB's GDT. So I took the code from https://github.com/psamora/DiOS and adapted it to my OS. But then, I got this:
Code:
00078174177e[CPU0 ] load_seg_reg(SS): not writable data segment
00078174177e[CPU0 ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00078174177e[CPU0 ] interrupt(): vector must be within IDT table limits, IDT.limit = 0x0
00078174177i[CPU0 ] CPU is in protected mode (active)
00078174177i[CPU0 ] CS.mode = 32 bit
00078174177i[CPU0 ] SS.mode = 32 bit
00078174177i[CPU0 ] EFER   = 0x00000000
00078174177i[CPU0 ] | EAX=00100010  EBX=00000000  ECX=00000004  EDX=000003d5
00078174177i[CPU0 ] | ESP=00108dbc  EBP=00000000  ESI=00000000  EDI=00000000
00078174177i[CPU0 ] | IOPL=0 id vip vif ac vm RF nt of df if tf sf zf af pf cf
00078174177i[CPU0 ] | SEG sltr(index|ti|rpl)     base    limit G D
00078174177i[CPU0 ] |  CS:0010( 0002| 0|  0) 00000000 ffffffff 1 1
00078174177i[CPU0 ] |  DS:0010( 0002| 0|  0) ffffffff ffffffff 1 1
00078174177i[CPU0 ] |  SS:0018( 0003| 0|  0) 00000000 ffffffff 1 1
00078174177i[CPU0 ] |  ES:0010( 0002| 0|  0) ffffffff ffffffff 1 1
00078174177i[CPU0 ] |  FS:0010( 0002| 0|  0) ffffffff ffffffff 1 1
00078174177i[CPU0 ] |  GS:0010( 0002| 0|  0) ffffffff ffffffff 1 1
00078174177i[CPU0 ] | EIP=001011df (001011df)
00078174177i[CPU0 ] | CR0=0x60000011 CR2=0x00000000
00078174177i[CPU0 ] | CR3=0x00000000 CR4=0x00000000
(0).[78174177] [0x00000000001011df] 0010:00000000001011df (unk. ctxt): mov ss, ax                ; 8ed0
00078174177p[CPU0 ] >>PANIC<< exception(): 3rd (13) exception with no resolution

My OS source code is available here: https://github.com/weedboi6969/puckos. Can someone help me with that?

_________________
Fusion: https://gitlab.com/weedboi6969/fusion


Top
 Profile  
 
 Post subject: Re: I cannot get GDT working
PostPosted: Fri Apr 13, 2018 1:53 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3315
Location: Chichester, UK
What size is an unsigned int?


Top
 Profile  
 
 Post subject: Re: I cannot get GDT working
PostPosted: Fri Apr 13, 2018 10:57 pm 
Offline

Joined: Fri Apr 13, 2018 10:18 am
Posts: 23
iansjack wrote:
What size is an unsigned int?

An unsigned int is 16-bit in size.

_________________
Fusion: https://gitlab.com/weedboi6969/fusion


Top
 Profile  
 
 Post subject: Re: I cannot get GDT working
PostPosted: Fri Apr 13, 2018 11:47 pm 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3315
Location: Chichester, UK
There's your error.


Top
 Profile  
 
 Post subject: Re: I cannot get GDT working
PostPosted: Sat Apr 14, 2018 12:07 am 
Offline

Joined: Fri Apr 13, 2018 10:18 am
Posts: 23
Nevermind, I got it to work. I was so dumb that I thought that an unsigned int is 16-bit and not 32-bit! So I changed all unsigned int variables to unsigned short variables and it worked.

_________________
Fusion: https://gitlab.com/weedboi6969/fusion


Top
 Profile  
 
 Post subject: Re: I cannot get GDT working
PostPosted: Sat Apr 14, 2018 12:23 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 3315
Location: Chichester, UK
That's not really the best solution. Ideally you would use types that specify their size and make no assumptions about the compiler.

Compare your code with that you copied.


Top
 Profile  
 
 Post subject: Re: I cannot get GDT working
PostPosted: Sat Jun 16, 2018 5:33 pm 
Offline
User avatar

Joined: Sat Jun 16, 2018 5:06 pm
Posts: 2
Location: Italy
iansjack wrote:
That's not really the best solution. Ideally you would use types that specify their size and make no assumptions about the compiler.

Compare your code with that you copied.

I was thinking the exact same thing. :)

It is one thing getting your code to work, but it is another thing to have it well-written - by "well-written" code, I'm referring to code which will be stable (but you can add in other factors as well, such as documentation, manageability and the neatness of the source code). Sometimes it can mean re-doing all the previous work on the specific module from scratch (or worse - occasionally the entire project), but believe me, it really pays off in the end. Code which wasn't well-written can easily bite you in the bottom and ruin your day, week, month, or longer.

I can think of another really good reason as to why it is important to consider ensuring the code is as well-written as can be, instead of simply caring about whether it working or not.. That reason would be... *drum roll please*... Vulnerabilities! The better the design of the feature implementation, as well as the actual code to implement that designed feature, you may potentially end up with functionality which will be harder to exploit (and thus the feature would be potentially more secure). Security is generally a critical factor when it comes to designing and developing a feature for implementation, and without that security factor, it simply is not a good design/design implementation (in my personal opinion).

'Assumption is the mother of all failures' (as Slade Wilson from the DC Arrow series would say). Verify over assuming and your days are likely to become more enjoyable!

[EDIT: Apologies for bumping an old thread, but I thought introducing the security factor would be a good idea].

_________________
- ImmortaleVBR


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: ggodw000 and 4 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