Page 7 of 20

Re: How to make a GDT?

Posted: Wed Oct 19, 2022 7:19 pm
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.

Re: How to make a GDT?

Posted: Wed Oct 19, 2022 7:42 pm
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?

Re: How to make a GDT?

Posted: Wed Oct 19, 2022 7:54 pm
by Octocontrabass

Re: How to make a GDT?

Posted: Wed Oct 19, 2022 10:26 pm
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?

Re: How to make a GDT?

Posted: Wed Oct 19, 2022 10:48 pm
by Octocontrabass
I don't think Make is aware that you've rebuilt/reinstalled libgcc. Delete crtbegin.o and crtend.o and try again.

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 12:28 am
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

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 9:15 am
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]

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 9:24 am
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.

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 9:28 am
by devc1
Can you provide a link to your OS in github ?

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 9:46 am
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.

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 9:53 am
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__'

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 10:09 am
by Octocontrabass
zap8600 wrote:That didn't work.
Looks like you need to delete kernel.o too.

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 10:13 am
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.

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 10:39 am
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.

Re: How to make a GDT?

Posted: Thu Oct 20, 2022 12:01 pm
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.