census logo
[bootcensus] / src / segm_asm.s
1 # pcboot - bootable PC demo/game kernel
2 # Copyright (C) 2018  John Tsiombikas <nuclear@member.fsf.org>
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY, without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
16
17         .data
18         .align 4
19 # memory reserved for setup_selectors
20 off:    .long 0
21 seg:    .short 0
22 # memory reserved for set_gdt
23 lim:    .short 0
24 addr:   .long 0
25
26         .text
27 # setup_selectors(uint16_t code, uint16_t data)
28 # loads the requested selectors to all the selector registers
29         .globl setup_selectors
30 setup_selectors:
31         # set data selectors directly
32         movl 8(%esp), %eax
33         movw %ax, %ss
34         movw %ax, %es
35         movw %ax, %ds
36         movw %ax, %gs
37         movw %ax, %fs
38         # set cs using a long jump
39         movl 4(%esp), %eax
40         movw %ax, (seg)
41         movl $ldcs, (off)
42         ljmp *off
43 ldcs:
44         ret
45
46 # set_gdt(uint32_t addr, uint16_t limit)
47 # loads the GDTR with the new address and limit for the GDT
48         .globl set_gdt
49 set_gdt:
50         movl 4(%esp), %eax
51         movl %eax, (addr)
52         movw 8(%esp), %ax
53         movw %ax, (lim)
54         lgdt (lim)
55         ret
56
57 # set_task_reg(uint16_t tss_selector)
58 # loads the TSS selector in the task register
59         .globl set_task_reg
60 set_task_reg:
61         mov 4(%esp), %eax
62         ltr 4(%esp)
63         ret