Having trouble with this GDT code snippet from the wiki.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
GreenJames
Posts: 1
Joined: Tue Aug 13, 2019 9:55 am

Having trouble with this GDT code snippet from the wiki.

Post by GreenJames »

I'm very new to OS development, I have just started my first real project about a week ago. I'm following the meaty skeleton guide, and so far I've gotten terminal scrolling, new lines, GRUB, etc. figured out. However, the past few days I've been losing my marbles over getting the IDT and interrupts set up. As of right now, I think I've gotten the IDT set up for the most part, however I haven't gotten a chance to test out interrupts yet. Part of the interrupts tutorial has this code snippet for GRUB users:

Code: Select all

  jmp load_gdt
 
  ;global descriptor table
  gdt:
 
  gdt_null:
  dq 0
 
  gdt_code:
  dw 0FFFFh
  dw 0
 
  db 0
  db 10011010b
  db 11001111b
  db 0
 
  gdt_data:
  dw 0FFFFh
  dw 0
 
  db 0
  db 10010010b
  db 11001111b
  db 0
 
  gdt_end:
 
  gdt_desc:
   dw gdt_end - gdt - 1
   dd gdt
 
  ;load gdt
  load_gdt:
    cli  ;disable interrupts
    lgdt [gdt_desc]  ;load GDT
    sti  ;enable interrupts

However when I use this code I get assembler errors:

Code: Select all

arch/i386/gdt.s: Assembler messages:
arch/i386/gdt.s:3: Error: no such instruction: `global descriptor table'
arch/i386/gdt.s:7: Error: no such instruction: `dq 0'
arch/i386/gdt.s:10: Error: no such instruction: `dw 0FFFFh'
arch/i386/gdt.s:11: Error: no such instruction: `dw 0'
arch/i386/gdt.s:13: Error: no such instruction: `db 0'
arch/i386/gdt.s:14: Error: no such instruction: `db 10011010b'
arch/i386/gdt.s:15: Error: no such instruction: `db 11001111b'
arch/i386/gdt.s:16: Error: no such instruction: `db 0'
arch/i386/gdt.s:19: Error: no such instruction: `dw 0FFFFh'
arch/i386/gdt.s:20: Error: no such instruction: `dw 0'
arch/i386/gdt.s:22: Error: no such instruction: `db 0'
arch/i386/gdt.s:23: Error: no such instruction: `db 10010010b'
arch/i386/gdt.s:24: Error: no such instruction: `db 11001111b'
arch/i386/gdt.s:25: Error: no such instruction: `db 0'
arch/i386/gdt.s:30: Error: no such instruction: `dw gdt_end - gdt - 1'
arch/i386/gdt.s:31: Error: no such instruction: `dd gdt'
arch/i386/gdt.s:33: Error: no such instruction: `load gdt'
arch/i386/gdt.s:35: Error: no such instruction: `disable interrupts'
arch/i386/gdt.s:36: Error: invalid char '[' beginning operand 1 `[gdt_desc]'
arch/i386/gdt.s:36: Error: no such instruction: `load GDT'
arch/i386/gdt.s:37: Error: no such instruction: `enable interrupts'
<builtin>: recipe for target 'arch/i386/gdt.o' failed
make: *** [arch/i386/gdt.o] Error 1

What am I doing wrong? I am using the GCC cross assembler and ATT syntax assembly.
no92
Member
Member
Posts: 307
Joined: Wed Oct 30, 2013 1:57 pm
Libera.chat IRC: no92
Location: Germany
Contact:

Re: Having trouble with this GDT code snippet from the wiki.

Post by no92 »

Are you sure about your statement that you use AT&T-style assembly? The error messages might be onto something ...
MichaelPetch
Member
Member
Posts: 797
Joined: Fri Aug 26, 2016 1:41 pm
Libera.chat IRC: mpetch

Re: Having trouble with this GDT code snippet from the wiki.

Post by MichaelPetch »

You are trying to assemble this code with GCC/GAS (Gnu assembler), but the code is for NASM. `gcc` nor `as` will assemble that code.

Meaty Skeleton's assembly code use GNU assembler AT&T syntax, the interrupt tutorial you are using uses NASM syntax.
Post Reply