title: How to change data segment? What am I doing wrong?
body: <p>I am developing a 32 bit OS and have developed a working ELF loader that works just fine. Now I do not have paging enabled (I plan to later, but right now I am just trying to load kernel modules) and I am trying to execute modules at boot. Basically since again at this time multitasking is not fully implemented I just want to load each module, call init (which will install interrupt handlers and just set up what ever the module is for) and then exit and execute the next one. It works, but I can not do anything with pointers in the C program (because it still thinks it is using the kernels data segment). So basically what I want to do is make a new data segment that points to the modules .data segment in RAM. I am doing this by setting entry number 6 in the GDT like.</p>
  
  <pre><code>setGDTEntry(6, DataAddress,DataSize, 0xF2, 0xCF);
  </code></pre>
  
  <p>The setEntry method works just fine, it looks like</p>
  
  <pre><code>void setGDTEntry(int num, uint Base, uint limit, byte access, byte gran)
  </code></pre>
  
  <p>Again both work 100%, the problem that I am having occurs when I change the data segment selector. I am doing this in assembly, the ELFs entry point is stored in EAX.</p>
  
  <pre><code>mov ax, 30h ; This is 8 * 6, the GDT entry containing the new data segment
  mov ds, ax ; set data segment
  call address ; JUMP!!!!
  mov ax, 0x10 ; Restore kernel data segment
  mov ds, ax ; set data segment
  </code></pre>
  
  <p>This will cause my kernel to panic, giving CPU exception 0x6, invalid opcode. The source code for my C Program is just a hello world program that copies text into video RAM (nothing much to see.). Does anyone know what I am doing wrong? I am new to the whole concept of the GDT and segment selectors.......... And  I can not have paging or multitasking enabled at this time, I really do not feel like explaining why....</p>