src/kernel/graphics.s (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
.section .text.realmode
.global realmode_int10h
realmode_int10h:
push %ebp
mov %esp, %ebp
pusha
push %ds
push %es
push %fs
push %ss
mov %cr3, %eax
push %eax
mov %esp, %eax
mov %eax, %esi
mov %ebp, %eax
mov %eax, %edi
# setup real mode stack
mov $0xF000, %eax
mov %eax, %esp
mov %eax, %ebp
push %esi
push %edi
# disable paging
xor %eax, %eax
mov %eax, %cr3
# switch to realmode temporarily
mov %cr0, %eax
and $0x3FFFFFFC, %eax
mov %eax, %cr0
# perform long jump to set code segment
ljmp $0, $realmode
return_pmode:
# set data segments
movw $0x10, %ax
movw %ax, %ss
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
# restore stack
pop %ebp
pop %eax
mov %eax, %esp
# restore original segments and registers
pop %eax
mov %eax, %cr3
pop %ss
pop %fs
pop %es
pop %ds
popa
# return
pop %ebp
.code16
realmode:
# setup real mode segments
movw $0x0000, %ax
movw %ax, %ss
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
# perform the actual interrupt
mov %cr0, %eax
and $0x00000001, %eax
mov %eax, %cr0
ljmp $0x8, $return_pmode