Page 1 of 1

[SOLVED]My OS boots on my laptop, but not on my desktop PC

Posted: Wed Mar 25, 2020 12:55 am
by tokusan
Hello.

Repository: https://github.com/toku-sa-n/ramen/tree/boot_with_uefi

My OS boots with UEFI. It runs under 64-bit mode. After exiting UEFI boot services, it changes paging settings and CR3 value. On my laptop, assigning a value to a valid virtual memory address succeeds. However, this action fails on my desktop PC.

Code: Select all

    MOV RAX, 0xFFFFFFFF80200000
    MOV QWORD[VRAM_PTR], RAX     ;  <--- crash on only my desktop PC.
MOV from memory to a register causes no problems on both my laptop and desktop PC.

Code: Select all

    MOV RAX, QWORD[VRAM_PTR]      ; <--- not crash.
Also, I found that changing the CR3 value wasn't the cause of the crash. Inserting JMP $ immediately after MOV CR3, RAX told me that.

Code: Select all

    MOV RAX, PML4
    MOV CR3, RAX                  ; <--- not crash.
These codes are written in asm/paging_64.asm. (https://github.com/toku-sa-n/ramen/blob ... 4.asm#L108)
Why does my OS crash on desktop PC?

Just in case: desktop PC

Code: Select all

%uname -a
Linux gentoo_desktop 5.5.11-gentoo #1 SMP Tue Mar 24 23:45:50 JST 2020 x86_64 Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz GenuineIntel GNU/Linux
laptop

Code: Select all

%uname -a
Linux laptop 5.4.12-gentoo #1 SMP Tue Jan 21 14:56:38 JST 2020 x86_64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz GenuineIntel GNU/Linux

Re: My OS boots on my laptop, but not on my desktop PC

Posted: Wed Mar 25, 2020 2:32 am
by sleephacker
As far as I can tell from your code you only set the 'present' bit (bit 0) in each paging structure entry, but you don't set the 'R/W' bit (bit 1). This means your pages are all marked as read-only.

Re: My OS boots on my laptop, but not on my desktop PC

Posted: Wed Mar 25, 2020 4:18 am
by iansjack
Note that this only prevents writes in supervisor mode if the CR0.WP flag is set to 1. It's possible that the UEFI in the two computers sets this differently and (as far as I can tell from the rather difficult to follow code) this is never explicitly cleared. This would explain why the code works on one computer but not on the other. This hypothesis can easily be tested by explicitly clearing the flag when paging is enabled.

Re: My OS boots on my laptop, but not on my desktop PC

Posted: Wed Mar 25, 2020 5:40 am
by tokusan
Thanks for replying. Both ways (setting R/W bit, and clearing CR0.WP) solved my problem!