How to make a GDT?

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
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote: The symbol name depends on the file name. Your font is named "font/unifont.sfn" instead of "console.sfn", so you need to replace "_binary_console_sfn_start" with "_binary_font_unifont_sfn_start".
I had my font named that because inside the kernel folder, I have a folder called font, which is where the file is. Thanks though.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

I'm now getting this error.

Code: Select all

mkdir -p /home/linuxlite/workspace/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/workspace/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/workspace/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/workspace/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/workspace/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/workspace/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/workspace/CCOS-new/sysroot/usr/lib
cp libk.a /home/linuxlite/workspace/CCOS-new/sysroot/usr/lib
mkdir -p /home/linuxlite/workspace/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/workspace/CCOS-new/sysroot/usr/include/.
x86_64-elf-gcc --sysroot=/home/linuxlite/workspace/CCOS-new/sysroot -isystem=/usr/include -T arch/x86_64/linker.ld -o myos.kernel -O2 -g -Wall -Wextra -ffreestanding -mcmodel=kernel -mno-red-zone    arch/x86_64/crti.o arch/x86_64/crtbegin.o arch/x86_64/tty.o  kernel/kernel.o unifont.o  -nostdlib -lk -lgcc  arch/x86_64/crtend.o arch/x86_64/crtn.o 
/home/linuxlite/opt/cross/lib/gcc/x86_64-elf/12.2.0/../../../../x86_64-elf/bin/ld: warning: myos.kernel has a LOAD segment with RWX permissions
`.eh_frame' referenced in section `.text' of arch/x86_64/crtbegin.o: defined in discarded section `.eh_frame' of arch/x86_64/crtbegin.o
`.eh_frame' referenced in section `.text' of arch/x86_64/crtbegin.o: defined in discarded section `.eh_frame' of arch/x86_64/crtbegin.o
arch/x86_64/crtbegin.o: in function `deregister_tm_clones':
crtstuff.c:(.text+0x1): relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__' defined in .dtors section in myos.kernel
crtstuff.c:(.text+0x18): relocation truncated to fit: R_X86_64_32 against `.tm_clone_table'
arch/x86_64/crtbegin.o: in function `register_tm_clones':
crtstuff.c:(.text+0x31): relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__' defined in .dtors section in myos.kernel
crtstuff.c:(.text+0x5a): relocation truncated to fit: R_X86_64_32 against `.tm_clone_table'
arch/x86_64/crtbegin.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x88): relocation truncated to fit: R_X86_64_32 against `.dtors'
crtstuff.c:(.text+0x8e): relocation truncated to fit: R_X86_64_32 against symbol `__DTOR_END__' defined in .dtors section in arch/x86_64/crtend.o
arch/x86_64/crtbegin.o: in function `frame_dummy':
crtstuff.c:(.text+0x10c): relocation truncated to fit: R_X86_64_32 against `.bss'
kernel/kernel.o: in function `_start':
/home/linuxlite/workspace/CCOS-new/kernel/kernel/kernel.c:7:(.text+0xc): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
arch/x86_64/crtend.o: in function `__do_global_ctors_aux':
crtstuff.c:(.text+0x13): relocation truncated to fit: R_X86_64_32 against `.ctors'
collect2: error: ld returned 1 exit status
make: *** [Makefile:57: myos.kernel] Error 1
I'm assuming that the linker.ld file needs to be modified. Am I correct?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

This didn't work. I got (what I think is) the same thing.

Code: Select all

mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c stdio/printf.c -o stdio/printf.libk.o -std=gnu11 -O2 -g -ffreestanding -Wall -Wextra   -D__is_libc -Iinclude -D__is_libk 
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c string/memcmp.c -o string/memcmp.libk.o -std=gnu11 -O2 -g -ffreestanding -Wall -Wextra   -D__is_libc -Iinclude -D__is_libk 
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c string/memcpy.c -o string/memcpy.libk.o -std=gnu11 -O2 -g -ffreestanding -Wall -Wextra   -D__is_libc -Iinclude -D__is_libk 
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c string/memmove.c -o string/memmove.libk.o -std=gnu11 -O2 -g -ffreestanding -Wall -Wextra   -D__is_libc -Iinclude -D__is_libk 
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c string/memset.c -o string/memset.libk.o -std=gnu11 -O2 -g -ffreestanding -Wall -Wextra   -D__is_libc -Iinclude -D__is_libk 
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c string/strlen.c -o string/strlen.libk.o -std=gnu11 -O2 -g -ffreestanding -Wall -Wextra   -D__is_libc -Iinclude -D__is_libk 
x86_64-elf-ar rcs libk.a stdio/printf.libk.o stdio/putchar.libk.o stdio/puts.libk.o stdlib/abort.libk.o string/memcmp.libk.o string/memcpy.libk.o string/memmove.libk.o string/memset.libk.o string/strlen.libk.o
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/lib
cp libk.a /home/linuxlite/help/CCOS-new/sysroot/usr/lib
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -MD -c arch/x86_64/tty.c -o arch/x86_64/tty.o -std=gnu11 -O2 -g -Wall -Wextra -ffreestanding -mcmodel=kernel -mno-red-zone   -D__is_kernel -Iinclude 
arch/x86_64/tty.c: In function 'terminal_initialize':
arch/x86_64/tty.c:14:18: warning: assignment to 'ssfn_font_t *' from incompatible pointer type 'volatile unsigned char *' [-Wincompatible-pointer-types]
   14 |         ssfn_src = &_binary_unifont_sfn_start;      /* the bitmap font to use */
      |                  ^
arch/x86_64/tty.c: In function 'terminal_putchar':
arch/x86_64/tty.c:32:29: warning: passing argument 1 of 'terminal_putentryat' makes pointer from integer without a cast [-Wint-conversion]
   32 |         terminal_putentryat(c);
      |                             ^
      |                             |
      |                             char
arch/x86_64/tty.c:23:32: note: expected 'char *' but argument is of type 'char'
   23 | void terminal_putentryat(char *s) {
      |                          ~~~~~~^
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -T arch/x86_64/linker.ld -o myos.kernel -O2 -g -Wall -Wextra -ffreestanding -mcmodel=kernel -mno-red-zone    arch/x86_64/crti.o arch/x86_64/crtbegin.o arch/x86_64/tty.o  kernel/kernel.o unifont.o  -nostdlib -lk -lgcc  arch/x86_64/crtend.o arch/x86_64/crtn.o 
/home/linuxlite/opt/cross/lib/gcc/x86_64-elf/12.2.0/../../../../x86_64-elf/bin/ld: warning: myos.kernel has a LOAD segment with RWX permissions
`.eh_frame' referenced in section `.text' of arch/x86_64/crtbegin.o: defined in discarded section `.eh_frame' of arch/x86_64/crtbegin.o
`.eh_frame' referenced in section `.text' of arch/x86_64/crtbegin.o: defined in discarded section `.eh_frame' of arch/x86_64/crtbegin.o
arch/x86_64/crtbegin.o: in function `deregister_tm_clones':
crtstuff.c:(.text+0x1): relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__' defined in .dtors section in myos.kernel
crtstuff.c:(.text+0x18): relocation truncated to fit: R_X86_64_32 against `.tm_clone_table'
arch/x86_64/crtbegin.o: in function `register_tm_clones':
crtstuff.c:(.text+0x31): relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__' defined in .dtors section in myos.kernel
crtstuff.c:(.text+0x5a): relocation truncated to fit: R_X86_64_32 against `.tm_clone_table'
arch/x86_64/crtbegin.o: in function `__do_global_dtors_aux':
crtstuff.c:(.text+0x88): relocation truncated to fit: R_X86_64_32 against `.dtors'
crtstuff.c:(.text+0x8e): relocation truncated to fit: R_X86_64_32 against symbol `__DTOR_END__' defined in .dtors section in arch/x86_64/crtend.o
arch/x86_64/crtbegin.o: in function `frame_dummy':
crtstuff.c:(.text+0x10c): relocation truncated to fit: R_X86_64_32 against `.bss'
kernel/kernel.o: in function `_start':
/home/linuxlite/workspace/CCOS-new/kernel/kernel/kernel.c:7:(.text+0xc): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
arch/x86_64/crtend.o: in function `__do_global_ctors_aux':
crtstuff.c:(.text+0x13): relocation truncated to fit: R_X86_64_32 against `.ctors'
collect2: error: ld returned 1 exit status
make: *** [Makefile:57: myos.kernel] Error 1
Am I just being dumb?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

I don't think Make is aware that you've rebuilt/reinstalled libgcc. Delete crtbegin.o and crtend.o and try again.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

Octocontrabass wrote: I don't think Make is aware that you've rebuilt/reinstalled libgcc. Delete crtbegin.o and crtend.o and try again.
That didn't work. Here is the output.

Code: Select all

mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/lib
cp libk.a /home/linuxlite/help/CCOS-new/sysroot/usr/lib
mkdir -p /home/linuxlite/help/CCOS-new/sysroot/usr/include
cp -R --preserve=timestamps include/. /home/linuxlite/help/CCOS-new/sysroot/usr/include/.
OBJ=`x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -O2 -g -Wall -Wextra -ffreestanding -mcmodel=kernel -mno-red-zone    -print-file-name=crtbegin.o` && cp "$OBJ" arch/x86_64/crtbegin.o
OBJ=`x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -O2 -g -Wall -Wextra -ffreestanding -mcmodel=kernel -mno-red-zone    -print-file-name=crtend.o` && cp "$OBJ" arch/x86_64/crtend.o
x86_64-elf-gcc --sysroot=/home/linuxlite/help/CCOS-new/sysroot -isystem=/usr/include -T arch/x86_64/linker.ld -o myos.kernel -O2 -g -Wall -Wextra -ffreestanding -mcmodel=kernel -mno-red-zone    arch/x86_64/crti.o arch/x86_64/crtbegin.o arch/x86_64/tty.o  kernel/kernel.o unifont.o  -nostdlib -lk -lgcc  arch/x86_64/crtend.o arch/x86_64/crtn.o 
/home/linuxlite/opt/cross/lib/gcc/x86_64-elf/12.2.0/../../../../x86_64-elf/bin/ld: warning: myos.kernel has a LOAD segment with RWX permissions
`.eh_frame' referenced in section `.text' of arch/x86_64/crtbegin.o: defined in discarded section `.eh_frame' of arch/x86_64/crtbegin.o
`.eh_frame' referenced in section `.text' of arch/x86_64/crtbegin.o: defined in discarded section `.eh_frame' of arch/x86_64/crtbegin.o
kernel/kernel.o: in function `_start':
/home/linuxlite/workspace/CCOS-new/kernel/kernel/kernel.c:7:(.text+0xc): relocation truncated to fit: R_X86_64_32 against `.rodata.str1.1'
collect2: error: ld returned 1 exit status
make: *** [Makefile:57: myos.kernel] Error 1
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: How to make a GDT?

Post by devc1 »

I didn't read your problem alot but I guess this happens while you are trying to switch your OS from 32 bit to 64 bit.


- When switching to 64 bit mode, if you want the address of a label you must add the "rel" prefix to relocateable symbols like the ones declared in the data and bss section. This will make nasm generate a 64 bit relocation entry.
So instead of :

Code: Select all

mov eax, [SomeVariable]
Type :

Code: Select all

mov eax, [rel SomeVariable]
Last edited by devc1 on Thu Oct 20, 2022 9:29 am, edited 1 time in total.
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

devc1 wrote: I didn't read your problem alot but I guess this happens while you are trying to switch your OS from 32 bit to 64 bit.
Yes.
devc1 wrote: - When switching to 32 bit mode, if you want the address of a label you must add the "rel" prefix to relocateable symbols like the ones declared in the data and bss section. This will make nasm generate a 64 bit relocation entry.
So instead of :

Code: Select all

mov eax, [SomeVariable]
Type :

Code: Select all

mov eax, [rel SomeVariable]
I'm not sure what you mean by this. I am not using nasm. I'm using the BOOTBOOT protocol. It starts my kernel in long mode at the start.
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: How to make a GDT?

Post by devc1 »

Can you provide a link to your OS in github ?
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

devc1 wrote:Can you provide a link to your OS in github ?
I can. I've been having some trouble with Github lately, so my code isn't there. I will upload have to upload the code sometime later. Sorry about that. The link is https://github.com/zap8600/CCOS-new.
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: How to make a GDT?

Post by devc1 »

However as I said before, the following message means that you're accessing the 32 bit relocated address of this symbol instead of the 64 bit one. Are you using your own CRT? If not then it is probably that your CRT is 32 bit and the linker only relocates 64 bit symbols.

relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__'
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: How to make a GDT?

Post by Octocontrabass »

zap8600 wrote:That didn't work.
Looks like you need to delete kernel.o too.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: How to make a GDT?

Post by nexos »

devc1 wrote:However as I said before, the following message means that you're accessing the 32 bit relocated address of this symbol instead of the 64 bit one. Are you using your own CRT? If not then it is probably that your CRT is 32 bit and the linker only relocates 64 bit symbols.

relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__'
libc /libgcc has nothing to do with this. The errors clearly came from his code.

You need to delete kernel.o so that gets rebuilt.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
zap8600
Member
Member
Posts: 195
Joined: Tue Nov 02, 2021 11:26 am
Libera.chat IRC: zap8600

Re: How to make a GDT?

Post by zap8600 »

devc1 wrote:However as I said before, the following message means that you're accessing the 32 bit relocated address of this symbol instead of the 64 bit one. Are you using your own CRT? If not then it is probably that your CRT is 32 bit and the linker only relocates 64 bit symbols.

relocation truncated to fit: R_X86_64_32 against symbol `__TMC_END__'
Are you talking about the crtn.S and crti.S files? If so, then I am using x86_64 files.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: How to make a GDT?

Post by nexos »

Like I said in my above post, it has nothing to do with that. Try deleting kernel.o and see what that does.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply