TSOS/src/boot/switch32.s

43 lines
1.4 KiB
ArmAsm

; Copyright 2022 Mattia Giambirtone & Contributors
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
; Utilities to switch to protected mode and load our GDT
[bits 16]
switch_to_protected_mode:
cli ; Now we disable interrupts
lgdt [gdt_descriptor] ; Time to load the GDT descriptor
; We set 32-bit mode in CR0. Almost done!
mov eax, cr0
or eax, 0x1
mov cr0, eax
jmp CODE_SEG:switch32 ; At last, we perform a far jump into a different segment
[bits 32]
switch32: ; We're not in 32 bit mode, yay!
mov ax, DATA_SEG ; Time to update the segment registers with their new values
mov ds, ax
mov ss, ax
mov es, ax
; Bonus: we have two more user-defined
; segment registers when in 32-bit mode
mov fs, ax
mov gs, ax
mov ebp, 0x1f8400 ; We also make the stack larger (2MiB)
mov esp, ebp
call BEGIN_32BIT ; We call back into mbr.s which loads the kernel