Paging problems

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.
MakaAlbarn001
Posts: 20
Joined: Fri Jun 16, 2017 1:51 am
Libera.chat IRC: Maka_Albarn

Re: Paging problems

Post by MakaAlbarn001 »

As to your first point, I'll do an "info reg" at _start to try to work out what's happening. On the point that you mentioned in your edit, I can't believe that I didn't notice that.
linuxyne
Member
Member
Posts: 211
Joined: Sat Jul 02, 2016 7:02 am

Re: Paging problems

Post by linuxyne »

It is also worthwhile to check the calling convention between boot32.s (which is compiled as code32) and paging.cpp (which is compiled as code64), as it applies when calling page_set.
MakaAlbarn001
Posts: 20
Joined: Fri Jun 16, 2017 1:51 am
Libera.chat IRC: Maka_Albarn

Re: Paging problems

Post by MakaAlbarn001 »

head... meet desk.

I am SUCH and IDIOT. Why did I not think to specify gcc to compile those bits of code as 32-bit I have no idea.
linuxyne
Member
Member
Posts: 211
Joined: Sat Jul 02, 2016 7:02 am

Re: Paging problems

Post by linuxyne »

I think I realized the situation a bit late :oops:.
A 32bit cpu, interpreting actual 64bit instructions as 32bit, seems to be the cause, unless something else turns up as the root cause for the weird behaviour.
MakaAlbarn001
Posts: 20
Joined: Fri Jun 16, 2017 1:51 am
Libera.chat IRC: Maka_Albarn

Re: Paging problems

Post by MakaAlbarn001 »

Not quite. A 64-bit cpu, running what should be 32-bit instructions as 64-bit, while in protected(32-bit) mode.
MakaAlbarn001
Posts: 20
Joined: Fri Jun 16, 2017 1:51 am
Libera.chat IRC: Maka_Albarn

Re: Paging problems

Post by MakaAlbarn001 »

Well. I managed to get my paging problem fixed by setting the page tables in my boot32.s file. Now I need to set the GDT. Can anyone translate this to AT&T assembly:

Code: Select all

GDT64:                           ; Global Descriptor Table (64-bit).
    .Null: equ $ - GDT64         ; The null descriptor.
    dw 0                         ; Limit (low).
    dw 0                         ; Base (low).
    db 0                         ; Base (middle)
    db 0                         ; Access.
    db 0                         ; Granularity.
    db 0                         ; Base (high).
    .Code: equ $ - GDT64         ; The code descriptor.
    dw 0                         ; Limit (low).
    dw 0                         ; Base (low).
    db 0                         ; Base (middle)
    db 10011010b                 ; Access (exec/read).
    db 00100000b                 ; Granularity.
    db 0                         ; Base (high).
    .Data: equ $ - GDT64         ; The data descriptor.
    dw 0                         ; Limit (low).
    dw 0                         ; Base (low).
    db 0                         ; Base (middle)
    db 10010010b                 ; Access (read/write).
    db 00000000b                 ; Granularity.
    db 0                         ; Base (high).
    .Pointer:                    ; The GDT-pointer.
    dw $ - GDT64 - 1             ; Limit.
    dq GDT64                     ; Base.
linuxyne
Member
Member
Posts: 211
Joined: Sat Jul 02, 2016 7:02 am

Re: Paging problems

Post by linuxyne »

Would it not be better to understand what the bits and pieces of such a table mean, and then write one of your own directly in your desired assembly?
MakaAlbarn001
Posts: 20
Joined: Fri Jun 16, 2017 1:51 am
Libera.chat IRC: Maka_Albarn

Re: Paging problems

Post by MakaAlbarn001 »

For the most part, it was only the offset sections, "equ $ - GDT64" that got me. I managed to figure most of it out.

Code: Select all

GDT64:
	.Null = . - GDT64
	.short 0
	.short 0
	.byte 0
	.byte 0
	.byte 0
	.byte 0
	.Code = . - GDT64
	.short 0
	.short 0
	.byte 0
	.byte 0x9A
	.byte 0x20
	.byte 0
	.Data = . - GDT64
	.short 0
	.short 0
	.byte 0
	.byte 0x92
	.byte 0
	.byte 0
	.Pointer:
	.short = . - GDT64 - 1
	.quad GDT64
My only remaining question is if I need to use $GDT64 instead of GDT64 in .pointer?

Edit: I did just realize that I couldn't use ".Code" or ".Data" for the GDT offsets because they might be assembled weirdly.

Edit 2: Okay, for some reason, when I try to set my data segment, it jumps to an entirely different area. Weird.
Post Reply