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

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
User avatar
tokusan
Member
Member
Posts: 29
Joined: Mon Feb 24, 2020 10:18 pm
Location: Japan

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

Post 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
Last edited by tokusan on Wed Mar 25, 2020 5:40 am, edited 1 time in total.
User avatar
sleephacker
Member
Member
Posts: 97
Joined: Thu Aug 06, 2015 6:41 am
Location: Netherlands

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

Post 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.
User avatar
iansjack
Member
Member
Posts: 4839
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
User avatar
tokusan
Member
Member
Posts: 29
Joined: Mon Feb 24, 2020 10:18 pm
Location: Japan

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

Post by tokusan »

Thanks for replying. Both ways (setting R/W bit, and clearing CR0.WP) solved my problem!
Post Reply