I cannot get GDT working

Programming, for all ages and all languages.
Post Reply
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

I cannot get GDT working

Post by itsmevjnk »

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: Select all

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?
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: I cannot get GDT working

Post by iansjack »

What size is an unsigned int?
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

Re: I cannot get GDT working

Post by itsmevjnk »

iansjack wrote:What size is an unsigned int?
An unsigned int is 16-bit in size.
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: I cannot get GDT working

Post by iansjack »

There's your error.
itsmevjnk
Member
Member
Posts: 32
Joined: Fri Apr 13, 2018 10:18 am
Location: Melbourne, VIC, Australia

Re: I cannot get GDT working

Post by itsmevjnk »

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.
Just a procrastinating uni student doing stupid things (or not doing them at all)...

SysX: https://github.com/itsmevjnk/sysx.git
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: I cannot get GDT working

Post by iansjack »

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.
User avatar
ImmortaleVBR
Posts: 2
Joined: Sat Jun 16, 2018 5:06 pm
Location: Italy

Re: I cannot get GDT working

Post by ImmortaleVBR »

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
Post Reply