Page 10 of 20

Re: How to make a GDT?

Posted: Sun Oct 23, 2022 6:10 pm
by Octocontrabass
zap8600 wrote:a lot of things say (bad) so maybe something is corrupted?
That's just what happens when you disassemble data as code.

What's the entry point address? (Use "objdump -f" or "readelf -h".)

Re: How to make a GDT?

Posted: Mon Oct 24, 2022 4:04 am
by devc1
I think from the previous thing that happened to me in the "Enabling optimizations ruins the kernel" topic, that he jumps to the entry point with a misaligned stack.

You must read the ABI.

If you "call EntryPoint" then the stack pointer must be 16 byte aligned.

if you "jmp EntryPoint" then the stack must be 16 byte aligned and you should push 8 bytes manually like :

"sub rsp, 8; jmp EntryPoint".

If you use optimizations, try compiling without them and see if it works. If yes, then you have some ABI problems

Re: How to make a GDT?

Posted: Mon Oct 24, 2022 4:14 am
by devc1
From my POV, The entry point function in a kernel should always be in assembly if you use a bootloader that is not yours. When your entry point is called, you must set your own stack pointer and Control registers, then jump to the kernel.

I personnaly allocate a small stack inside the kernel image.

So you can make the entry point like this :

Code: Select all

KernelSetup:
mov rbp, StackTop
mov rsp, rbp
; Reset RFLAGS (optionnal) to delete some Nested task and unwanted flags
push qword 0
popf
; Here you can setup control registers (optionnal)

; Now lets call the entry point
sub rsp, 8 ; Fake RIP
jmp _start

section .bss
align 0x1000
StackBottom resb 0x10000
StackTop:

Re: How to make a GDT?

Posted: Mon Oct 24, 2022 11:30 am
by zap8600
devc1 wrote:From my POV, The entry point function in a kernel should always be in assembly if you use a bootloader that is not yours. When your entry point is called, you must set your own stack pointer and Control registers, then jump to the kernel.

I personnaly allocate a small stack inside the kernel image.

So you can make the entry point like this :

Code: Select all

KernelSetup:
mov rbp, StackTop
mov rsp, rbp
; Reset RFLAGS (optionnal) to delete some Nested task and unwanted flags
push qword 0
popf
; Here you can setup control registers (optionnal)

; Now lets call the entry point
sub rsp, 8 ; Fake RIP
jmp _start

section .bss
align 0x1000
StackBottom resb 0x10000
StackTop:
I tried this, but I got these errors.

Code: Select all

arch/x86_64/boot.S: Assembler messages:
arch/x86_64/boot.S:11: Error: too many memory references for `mov'
arch/x86_64/boot.S:12: Error: too many memory references for `mov'

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 1:18 am
by devc1
This is in nasm syntax. You are using at&t syntax.

I don't know about at&t syntax alot, convert my code to your syntax then compile it.

I'm not sure, try this :
If there is any error, tell me.
I repeat, I am not experienced in this syntax. Just try this and see if it works.

Code: Select all

KernelSetup:
movq $StackTop, %rsp
movq %rbp, %rsp
# Reset RFLAGS (optionnal) to delete some Nested task and unwanted flags
pushq $0
popfq
# Here you can setup control registers (optionnal)

# Now lets call the entry point
subq $8, %rsp ; Fake RIP
jmp $_start

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 7:30 am
by zap8600
devc1 wrote:This is in nasm syntax. You are using at&t syntax.

I don't know about at&t syntax alot, convert my code to your syntax then compile it.

I'm not sure, try this :
If there is any error, tell me.
I repeat, I am not experienced in this syntax. Just try this and see if it works.

Code: Select all

KernelSetup:
movq $StackTop, %rsp
movq %rbp, %rsp
# Reset RFLAGS (optionnal) to delete some Nested task and unwanted flags
pushq $0
popfq
# Here you can setup control registers (optionnal)

# Now lets call the entry point
subq $8, %rsp ; Fake RIP
jmp $_start
It did work, but didn't solve my main issue. I 'm looking at the QEMU log to see if anything changed. if you need to see it, here it is.

Code: Select all

WARNING: Image format was not specified for 'myos.img' and probing guessed raw.
         Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
         Specify the 'raw' format explicitly to remove the restrictions.
SMM: enter
EAX=00000001 EBX=00000000 ECX=02000000 EDX=02000628
ESI=0000000b EDI=02000000 EBP=000f2c72 ESP=00006d98
EIP=000ebaef EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00cf9b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00cf9300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000080 CCD=00000001 CCO=LOGICB  
EFER=0000000000000000
SMM: after RSM
EAX=00000001 EBX=00000000 ECX=02000000 EDX=02000628
ESI=0000000b EDI=02000000 EBP=000f2c72 ESP=00006d98
EIP=000ebaef EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006dff
ESI=00006d3c EDI=07fbedc5 EBP=00006cfc ESP=00006cfc
EIP=00007bfb EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 008f9300
CS =f000 000f0000 ffffffff 008f9b00
SS =0000 00000000 ffffffff 008f9300
DS =0000 00000000 ffffffff 008f9300
FS =0000 00000000 ffffffff 008f9300
GS =0000 00000000 ffffffff 008f9300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000004 CCD=00006cfc CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006dff
ESI=00006d3c EDI=07fbedc5 EBP=00006cfc ESP=00006cfc
EIP=000f7bfc EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=07fabb00
ESI=000ea600 EDI=07fbedc5 EBP=00006cfc ESP=00006cfc
EIP=000f7c15 EFL=00000016 [----AP-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000014 CCD=00006ce8 CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=07fabb00
ESI=000ea600 EDI=07fbedc5 EBP=00006cfc ESP=00006cfc
EIP=00007c16 EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =0000 00000000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000004 CCD=00000001 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a22 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=00007bfb EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 008f9300
CS =f000 000f0000 ffffffff 008f9b00
SS =0000 00000000 ffffffff 008f9300
DS =0000 00000000 ffffffff 008f9300
FS =0000 00000000 ffffffff 008f9300
GS =ca00 000ca000 ffffffff 008f9300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000004 CCD=000069e2 CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a22 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=000f7bfc EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000005
ESI=00000000 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=000f7c15 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=000069ce CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000005
ESI=00000000 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=00007c16 EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000004 CCD=00000001 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a1c EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=00007bfb EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=000069dc CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a1c EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=000f7bfc EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000003
ESI=07f8cb00 EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=000f7c15 EFL=00000012 [----A--] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000010 CCD=000069c8 CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000003
ESI=07f8cb00 EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=00007c16 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000001 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a22 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=00007bfb EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000004 CCD=000069e2 CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a22 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=000f7bfc EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000005
ESI=00000000 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=000f7c15 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=000069ce CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000005
ESI=00000000 EDI=07fbedc5 EBP=000069e2 ESP=000069e2
EIP=00007c16 EFL=00000006 [-----P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000004 CCD=00000001 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a1c EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=00007bfb EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=000069dc CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=000f7bfc ECX=00001234 EDX=00006aff
ESI=00006a1c EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=000f7bfc EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000000 CCO=EFLAGS  
EFER=0000000000000000
SMM: enter
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000003
ESI=07eccb00 EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=000f7c15 EFL=00000012 [----A--] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
CS =0008 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA]
SS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
DS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
FS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
GS =0010 00000000 ffffffff 00c09300 DPL=0 DS   [-WA]
LDT=0000 00000000 0000ffff 00008200 DPL=0 LDT
TR =0000 00000000 0000ffff 00008b00 DPL=0 TSS32-busy
GDT=     000f6280 00000037
IDT=     000f62be 00000000
CR0=00000011 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000010 CCD=000069c8 CCO=EFLAGS  
EFER=0000000000000000
SMM: after RSM
EAX=000000b5 EBX=00007c16 ECX=00005678 EDX=00000003
ESI=07eccb00 EDI=07fbedc5 EBP=000069dc ESP=000069dc
EIP=00007c16 EFL=00000002 [-------] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =db80 000db800 ffffffff 00809300
CS =f000 000f0000 ffffffff 00809b00
SS =0000 00000000 ffffffff 00809300
DS =0000 00000000 ffffffff 00809300
FS =0000 00000000 ffffffff 00809300
GS =ca00 000ca000 ffffffff 00809300
LDT=0000 00000000 0000ffff 00008200
TR =0000 00000000 0000ffff 00008b00
GDT=     00000000 00000000
IDT=     00000000 000003ff
CR0=00000010 CR2=00000000 CR3=00000000 CR4=00000000
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=00000000 CCD=00000001 CCO=EFLAGS  
EFER=0000000000000000
check_exception old: 0xffffffff new 0xd
     0: v=0d e=0000 i=0 cpl=0 IP=0008:f000ff53f000ff53 pc=f000ff53f000ff53 SP=0010:0000000000000008 env->regs[R_EAX]=ffffffffffe033d8
RAX=ffffffffffe033d8 RBX=0000000000000000 RCX=00000000c0000001 RDX=0000000000000000
RSI=0000000000003c2a RDI=0000000000000000 RBP=0000000000001e91 RSP=0000000000000008
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=f000ff53f000ff53 RFL=00200046 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
CS =0008 0000000000000000 0000ffff 00209800 DPL=0 CS64 [---]
SS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
DS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
FS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
GS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     0000000000003220 00000027
IDT=     0000000000000000 000003ff
CR0=c0000011 CR2=0000000000000000 CR3=000000000000a000 CR4=00000368
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=ffffffffffe033d8 CCD=0000000000000000 CCO=SUBQ    
EFER=0000000000000500
check_exception old: 0xd new 0xd
     1: v=08 e=0000 i=0 cpl=0 IP=0008:f000ff53f000ff53 pc=f000ff53f000ff53 SP=0010:0000000000000008 env->regs[R_EAX]=ffffffffffe033d8
RAX=ffffffffffe033d8 RBX=0000000000000000 RCX=00000000c0000001 RDX=0000000000000000
RSI=0000000000003c2a RDI=0000000000000000 RBP=0000000000001e91 RSP=0000000000000008
R8 =0000000000000000 R9 =0000000000000000 R10=0000000000000000 R11=0000000000000000
R12=0000000000000000 R13=0000000000000000 R14=0000000000000000 R15=0000000000000000
RIP=f000ff53f000ff53 RFL=00200046 [---Z-P-] CPL=0 II=0 A20=1 SMM=0 HLT=0
ES =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
CS =0008 0000000000000000 0000ffff 00209800 DPL=0 CS64 [---]
SS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
DS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
FS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
GS =0010 0000000000000000 0fffffff 00809300 DPL=0 DS   [-WA]
LDT=0000 0000000000000000 0000ffff 00008200 DPL=0 LDT
TR =0000 0000000000000000 0000ffff 00008b00 DPL=0 TSS64-busy
GDT=     0000000000003220 00000027
IDT=     0000000000000000 000003ff
CR0=c0000011 CR2=0000000000000000 CR3=000000000000a000 CR4=00000368
DR0=0000000000000000 DR1=0000000000000000 DR2=0000000000000000 DR3=0000000000000000 
DR6=00000000ffff0ff0 DR7=0000000000000400
CCS=ffffffffffe033d8 CCD=0000000000000000 CCO=SUBQ    
EFER=0000000000000500
check_exception old: 0x8 new 0xd
I did change some of the code, though. That might be why. Here is my boot.S file if you need to see it.

Code: Select all

.section .bss
.align 16
stack_bottom:
.skip 16384 # 16 KiB
stack_top:

.section .text
.global _start
.type _start, @function
_start:
    movq $stack_top, %rsp
    movq %rbp, %rsp

    call kernel_main

    cli
1:	hlt
	jmp 1b
.size _start, . - _start


Re: How to make a GDT?

Posted: Tue Oct 25, 2022 8:52 am
by devc1
The last register dump has RSP set to 0x8.
There is something unusual.

Can you insert a "jmp $" before jumping to the kernel entry point and send the cpu registers dump. type in qemu monitor "info registers".

And tell me if no error happens when you do that.

You must set KernelSetup as the EntryPoint of the kernel.

Edit it to this :

Code: Select all

_start:
    movq $stack_top, %rsp
    movq %rbp, %rsp
### I just copied you, just make an infinite loop (not cli; hlt)
2:
    jmp 2b
    call kernel_main

    cli
1:   hlt
   jmp 1b

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 11:21 am
by nexos
Your assembly you changed in fine, and honestly makes a bit more sense than the original example. TBH I somewhat doubt the necessity of the assembly, but it's not hurting anything....

Run readelf -a on your kernel file, and give the results here. Also, please attach it as a file instead of dumping the whole thing here (as that makes it easier for people who want to skim the thread only).

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 11:47 am
by zap8600
devc1 wrote:The last register dump has RSP set to 0x8.
There is something unusual.

Can you insert a "jmp $" before jumping to the kernel entry point and send the cpu registers dump. type in qemu monitor "info registers".

And tell me if no error happens when you do that.

You must set KernelSetup as the EntryPoint of the kernel.

Edit it to this :

Code: Select all

_start:
    movq $stack_top, %rsp
    movq %rbp, %rsp
### I just copied you, just make an infinite loop (not cli; hlt)
2:
    jmp 2b
    call kernel_main

    cli
1:   hlt
   jmp 1b
This didn't work. It never got to the infinite loop.
nexos wrote:Your assembly you changed in fine, and honestly makes a bit more sense than the original example. TBH I somewhat doubt the necessity of the assembly, but it's not hurting anything....

Run readelf -a on your kernel file, and give the results here. Also, please attach it as a file instead of dumping the whole thing here (as that makes it easier for people who want to skim the thread only).
I've attached the file.

I may try using the BOOTBOOT example kernel as a base and rebuild the Meaty Skeleton code (in x86_64) from there.

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 12:07 pm
by nexos
Hmm, I don't see your entry point in the output. What's your linker command line?

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 12:16 pm
by devc1
So inserting an infinite loop at the very startup function of the kernel doesn't work ?

Then this is a bootloader ot linker problem I guess ?

Can you send us a github repo so I can try your code myself

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 12:27 pm
by zap8600
nexos wrote:Hmm, I don't see your entry point in the output. What's your linker command line?
I've taken the linker command from the output. This is the linking command.

Code: Select all

x86_64-elf-gcc --sysroot=/workspaces/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 -mno-mmx -mno-sse -mno-sse2    arch/x86_64/crti.o arch/x86_64/crtbegin.o arch/x86_64/boot.o arch/x86_64/tty.o  kernel/kernel.o font.o   -nostdlib -lk -lgcc  arch/x86_64/crtend.o arch/x86_64/crtn.o
devc1 wrote:So inserting an infinite loop at the very startup function of the kernel doesn't work ?

Then this is a bootloader ot linker problem I guess ?

Can you send us a github repo so I can try your code myself
The Github repo is here.

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 12:49 pm
by devc1
Did your kernel even compile ?

I get alot of errors.

When I fixed them, I got linker errors.

I am not a linux user, but if you use Windows, I can help you to compile your kernel without the wsl. And compiling on windows is much easier than on linux.

Code: Select all

cc -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/boot.o arch/x86_64/tty.o  kernel/kernel.o font.o   -nostdlib -lgcc  arch/x86_64/crtend.o arch/x86_64/crtn.o
/usr/bin/ld: arch/x86_64/crtbegin.o: relocation R_X86_64_32 against hidden symbol `__TMC_END__' can not be used when making a PIE object
/usr/bin/ld: arch/x86_64/boot.o: relocation R_X86_64_32S against `.bss' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: arch/x86_64/tty.o: relocation R_X86_64_32S against symbol `_binary_font_sfn_start' can not be used when making a PIE object; recompile with -fPIE
/usr/bin/ld: kernel/kernel.o: relocation R_X86_64_32S against `.rodata.str1.1' can not be used when making a PIE object; recompile with -fPIE

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 1:46 pm
by nexos
devc1 wrote:, I can help you to compile your kernel without the wsl. And compiling on windows is much easier than on linux.
What? Citation needed! Everyone agrees that making an OS on Linux is easier. Doing so on Windows is a nightmare!

The problem your having with compiling is rather simple. You need to use a cross compiler.

zap8600, I am honestly at a loss at this point. I would recommend ditching BOOTBOOT TBH. BOOTBOOT is very finicky from what I've seen. Try using Limine instead.

Re: How to make a GDT?

Posted: Tue Oct 25, 2022 2:24 pm
by devc1
No, in Windows you can just use msvc and nasm.
No cross compiling !
And nothing such as linker.ld makefile blablabla...
You can use wsl to use some of the linux things, but they all are not required (atleast because I've created my own fs drivers).