StupidOS/kernel/gdt.s

93 lines
1.6 KiB
ArmAsm
Raw Normal View History

2023-06-05 08:03:05 +00:00
; file: gdt.s
;
;
2023-01-15 19:25:25 +00:00
[BITS 32]
2023-07-02 14:47:18 +00:00
%include "cpu.inc"
2023-01-15 19:25:25 +00:00
section .text
2023-07-02 14:47:18 +00:00
; Function: gdt_setup
2023-06-05 08:03:05 +00:00
;
; in:
; none
;
; out:
; none
;
2023-07-02 14:47:18 +00:00
global gdt_setup
gdt_setup:
2023-01-15 19:25:25 +00:00
lgdt [gdt_ptr]
2023-05-22 12:01:20 +00:00
mov eax, cr0
or al, 1
mov cr0, eax
2023-01-15 19:25:25 +00:00
jmp 0x08:.flush_cs
.flush_cs:
2023-01-17 14:36:21 +00:00
mov ax, 0x10 ; data segment
2023-01-15 19:25:25 +00:00
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
ret
section .data
gdt_ptr:
dw gdt_entries.end - gdt_entries - 1
dd gdt_entries
gdt_entries:
;; null descriptor
2023-01-17 14:36:21 +00:00
dd 0x0
dd 0x0
2023-01-15 19:25:25 +00:00
;; kernel mode code segment
2023-07-02 14:47:18 +00:00
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0x9A
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
2023-01-15 19:25:25 +00:00
;; kernel mode data segment
2023-07-02 14:47:18 +00:00
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0x92
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
2023-01-15 19:25:25 +00:00
;; user mode code segment
2023-07-02 14:47:18 +00:00
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0xFA
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
2023-01-15 19:25:25 +00:00
;; user mode data segment
2023-07-02 14:47:18 +00:00
istruc gdt_entry
at gdt_entry.limit_low, dw 0xFFFF
at gdt_entry.base_low, dw 0x0000
at gdt_entry.base_mid, db 0x00
at gdt_entry.access, db 0xF2
at gdt_entry.flags, db 0xCF
at gdt_entry.base_high, db 0x00
iend
2023-01-15 19:25:25 +00:00
2023-07-02 14:47:18 +00:00
;;.tss:
2023-01-15 19:25:25 +00:00
;; TSS
2023-07-02 14:47:18 +00:00
;;istruc gdt_entry
;; at gdt_entry.access, db 0x89
;; at gdt_entry.flags, db 0x0
;;iend
2023-01-15 19:25:25 +00:00
.end: