Merge pull request #15 from E-Almqvist/dev

32bit Protected Mode
pull/25/head
Elias Almqvist 3 years ago committed by GitHub
commit ff653f1ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      src/bootloader.asm
  2. 35
      src/pm.asm
  3. 43
      src/pm/gdt.asm

@ -6,26 +6,8 @@
mov bp, 0x8000 ; move it to 0x8000 mov bp, 0x8000 ; move it to 0x8000
mov sp, bp mov sp, bp
; Print the welcome string ; Switching to PM
mov bx, welcome_string call pm_preinit
call println
; Read second sector (outside bootsector)
mov bx, 0x9000 ; LOAD LOCATION
mov dh, 2 ; SECTOR-COUNT
mov dl, [BOOT_DRIVE] ; DISK-INDEX
call disk_read
; Print out whatever bloated data that was read
mov dx, [0x9000]
call print_hex
mov bx, [ASCII_END]
call println
mov dx, [0x9000 + 512] ; read from second sector too
call print_hex
jmp $ ; inf loop jmp $ ; inf loop
@ -33,8 +15,13 @@
%include "bios.asm" %include "bios.asm"
%include "pm.asm" %include "pm.asm"
; Data BEGIN_PM:
welcome_string: db "e Operating-System (eOS)", ASCII_CARRIAGE_RETURN, ASCII_LINEBREAK, "Version 2021 0.0", ASCII_END mov ebx, welcome_string
call vga_print
jmp $
welcome_string: db "e Operating-System (eOS): Version 2021 0.0", ASCII_END
BOOT_DRIVE: db 0 BOOT_DRIVE: db 0
; Bootsector ; Bootsector

@ -1,2 +1,37 @@
; Utils
%include "equ/vga.asm" %include "equ/vga.asm"
%include "pm/vga/print.asm" %include "pm/vga/print.asm"
; GDT & switching to PM
%include "pm/gdt.asm" ; GDT defined here
; Switching to PM
[bits 16]
pm_preinit:
cli ; Switch interupts
lgdt [gdt_descriptor] ; Tell the CPU about the GDT
mov eax, cr0 ; Set first bit of the CR0 register
or eax, 0x1 ; to 1
mov cr0, eax ; Update the control register
; Initialize PM
jmp GDT_CODE_SEG:pm_init
[bits 32]
; Init registers & stack when in PM
pm_init:
mov ax, GDT_DATA_SEG ; Point the segment registers to GDT_DATA_SEG
; Segment registers
mov ds, ax
mov ss, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x900000 ; Update the stack pointer
mov esp, ebp
call BEGIN_PM

@ -0,0 +1,43 @@
; GDT
gdt_start:
gdt_null: ; NULL descriptor
dd 0x0 ; 4-bytes of
dd 0x0 ; 0x0 (0) = NULL
gdt_code: ; Code SD
; Range: 0x0 - 0xfffff
; Flags1: 1001b (present:2 privilege:descriptor type)
; Type: 1010b (code:conforming:readable:accessed)
; Flags2: 1100b (granularity:32bit default:64bit seg:AVL)
dw 0xffff ; Limit (bits 0-15)
dw 0x0 ; Base (bits 0-15)
db 0x0 ; Base (bits 16-23)
db 10011010b ; Flags1 : Type
db 11001111b ; Flags2 : Limit (16-19)
db 0x0 ; Base (bits 24-31)
gdt_data: ; Data SD
; Same flags as gdt_code but different type flags
; Type: 0010b (code:expand dowm:writable:accessed)
dw 0xffff ; Limit (bits 0-15)
dw 0x0 ; Base (bits 0-15)
db 0x0 ; Base (bits 16-23)
db 10010010b ; Flags1 : Type
db 11001111b ; Flags2 : Limit (16-19)
db 0x0 ; Base (bits 24-31)
gdt_end: ; Mark the end so we can get the delta-memory (size of GDT)
; GDT descriptor
gdt_descriptor:
dw gdt_end - gdt_start - 1 ; Size of GDT is always -1 of actual size (WHY?!?!?!?!??!)
dd gdt_start ; Pointer to the GDT
; Lazy constants
GDT_CODE_SEG equ gdt_code - gdt_start
GDT_DATA_SEG equ gdt_data - gdt_start
Loading…
Cancel
Save