diff options
Diffstat (limited to 'src/boot.s')
-rw-r--r-- | src/boot.s | 110 |
1 files changed, 96 insertions, 14 deletions
@@ -38,19 +38,100 @@ stack_top: ; Declare _start as a function symbol with the given symbol size. section .text -global _gdt_flush ; Allows the C code to link to this -extern _gp ; Says that '_gp' is in another file -_gdt_flush: - lgdt [_gp] ; Load the GDT with our '_gp' which is a special pointer - mov ax, 0x10 ; 0x10 is the offset in the GDT to our data segment - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - mov ss, ax - jmp 0x08:flush2 ; 0x08 is the offset to our code segment: Far jump! -flush2: - ret ; Returns back to the C code! +global reloadSegments ; Flush GDT +reloadSegments: + ; Reload CS register containing code selector: + JMP 0x08:reload_CS ; 0x08 points at the new code selector +reload_CS: + ; Reload data segment registers: + MOV AX, 0x10 ; 0x10 points at the new data selector + MOV DS, AX + MOV ES, AX + MOV FS, AX + MOV GS, AX + MOV SS, AX + RET + +%macro ISR_NOERRCODE 1 ; define a macro, taking one parameter + [GLOBAL isr%1] ; %1 accesses the first parameter. + isr%1: + cli + push byte 0 + push byte %1 + jmp isr_common_stub +%endmacro + +%macro ISR_ERRCODE 1 + [GLOBAL isr%1] + isr%1: + cli + push byte %1 + jmp isr_common_stub +%endmacro + +ISR_NOERRCODE 0 +ISR_NOERRCODE 1 +ISR_NOERRCODE 2 +ISR_NOERRCODE 3 +ISR_NOERRCODE 4 +ISR_NOERRCODE 5 +ISR_NOERRCODE 6 +ISR_NOERRCODE 7 +ISR_NOERRCODE 8 +ISR_NOERRCODE 9 +ISR_NOERRCODE 10 +ISR_NOERRCODE 11 +ISR_NOERRCODE 12 +ISR_NOERRCODE 13 +ISR_NOERRCODE 14 +ISR_NOERRCODE 15 +ISR_NOERRCODE 16 +ISR_NOERRCODE 17 +ISR_NOERRCODE 18 +ISR_NOERRCODE 19 +ISR_NOERRCODE 20 +ISR_NOERRCODE 21 +ISR_NOERRCODE 22 +ISR_NOERRCODE 23 +ISR_NOERRCODE 24 +ISR_NOERRCODE 25 +ISR_NOERRCODE 26 +ISR_NOERRCODE 27 +ISR_NOERRCODE 28 +ISR_NOERRCODE 29 +ISR_NOERRCODE 30 +ISR_NOERRCODE 31 + + +[EXTERN isr_handler] + +; This is our common ISR stub. It saves the processor state, sets +; up for kernel mode segments, calls the C-level fault handler, +; and finally restores the stack frame. +isr_common_stub: + pusha ; Pushes edi,esi,ebp,esp,ebx,edx,ecx,eax + + mov ax, ds ; Lower 16-bits of eax = ds. + push eax ; save the data segment descriptor + + mov ax, 0x10 ; load the kernel data segment descriptor + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + + call isr_handler + + pop eax ; reload the original data segment descriptor + mov ds, ax + mov es, ax + mov fs, ax + mov gs, ax + + popa ; Pops edi,esi,ebp... + add esp, 8 ; Cleans up the pushed error code and pushed ISR number + sti + iret ; pops 5 things at once: CS, EIP, EFLAGS, SS, and ESP global _start:function (_start.end - _start) _start: @@ -69,7 +150,8 @@ _start: ; stack (as it grows downwards on x86 systems). This is necessarily done ; in assembly as languages such as C cannot function without a stack. mov esp, stack_top - + + ; This is a good place to initialize crucial processor state before the ; high-level kernel is entered. It's best to minimize the early ; environment where crucial features are offline. Note that the |