OSDev.org
https://forum.osdev.org/

I cannot get GDT working
https://forum.osdev.org/viewtopic.php?f=13&t=32861
Page 1 of 1

Author:  itsmevjnk [ Fri Apr 13, 2018 10:22 am ]
Post subject:  I cannot get GDT working

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?

Author:  iansjack [ Fri Apr 13, 2018 1:53 pm ]
Post subject:  Re: I cannot get GDT working

What size is an unsigned int?

Author:  itsmevjnk [ Fri Apr 13, 2018 10:57 pm ]
Post subject:  Re: I cannot get GDT working

iansjack wrote:
What size is an unsigned int?

An unsigned int is 16-bit in size.

Author:  iansjack [ Fri Apr 13, 2018 11:47 pm ]
Post subject:  Re: I cannot get GDT working

There's your error.

Author:  itsmevjnk [ Sat Apr 14, 2018 12:07 am ]
Post subject:  Re: I cannot get GDT working

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.

Author:  iansjack [ Sat Apr 14, 2018 12:23 am ]
Post subject:  Re: I cannot get GDT working

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.

Author:  ImmortaleVBR [ Sat Jun 16, 2018 5:33 pm ]
Post subject:  Re: I cannot get GDT working

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].

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/