warning and chance to abort
[com32] / src / segm_s.asm
1 ; pcboot - bootable PC demo/game kernel
2 ; Copyright (C) 2018-2023  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         section .data
18         align 4
19 ; memory reserved for setup_selectors
20 off:    dd 0
21 segm:   dw 0
22 ; memory reserved for set_gdt
23 lim:    dw 0
24 addr:   dd 0
25
26         section .text
27 ; setup_selectors(uint16_t code, uint16_t data)
28 ; loads the requested selectors to all the selector registers
29         global setup_selectors
30 setup_selectors:
31         ; set data selectors directly
32         mov eax, [esp + 8]
33         mov ss, ax
34         mov es, ax
35         mov ds, ax
36         mov gs, ax
37         ;mov fs, ax     ; XXX don't touch fs, we use it to store initial seg
38         ; set cs using a long jump
39         mov eax, [esp + 4]
40         mov [segm], ax
41         mov dword [off], .ldcs
42         jmp [off]
43 .ldcs:  ret
44
45 ; set_gdt(uint32_t addr, uint16_t limit)
46 ; loads the GDTR with the new address and limit for the GDT
47         global set_gdt
48 set_gdt:
49         mov eax, [esp + 4]
50         mov [addr], eax
51         mov ax, [esp + 8]
52         mov [lim], ax
53         lgdt [lim]
54         ret
55
56 ; set_task_reg(uint16_t tss_selector)
57 ; loads the TSS selector in the task register
58         global set_task_reg
59 set_task_reg:
60         mov eax, [esp + 4]
61         ltr [esp + 4]
62         ret
63
64 ; vi:set ts=8 sts=8 sw=8 ft=nasm: