Remove interrupt setup from asm bootloader, add io module, memcpy functions, and serial driver
This commit is contained in:
parent
799b77d11a
commit
42c9ba12dc
17 changed files with 422 additions and 264 deletions
|
@ -1,105 +0,0 @@
|
|||
struc IDTEntry
|
||||
.offsetl resw 1
|
||||
.selector resw 1
|
||||
.zero resb 1
|
||||
.attribute resb 1
|
||||
.offseth resw 1
|
||||
endstruc
|
||||
|
||||
SECTION .text
|
||||
USE32
|
||||
|
||||
interrupts:
|
||||
.first:
|
||||
mov [.entry], byte 0
|
||||
jmp dword .handle
|
||||
.second:
|
||||
%assign i 1
|
||||
%rep 255
|
||||
mov [.entry], byte i
|
||||
jmp dword .handle
|
||||
%assign i i+1
|
||||
%endrep
|
||||
.handle:
|
||||
push ebp
|
||||
push esi
|
||||
push edi
|
||||
push edx
|
||||
push ecx
|
||||
push ebx
|
||||
push eax
|
||||
|
||||
push esp
|
||||
push dword [.entry]
|
||||
|
||||
mov eax, gdt.kernel_data
|
||||
mov ds, eax
|
||||
mov es, eax
|
||||
mov fs, eax
|
||||
mov gs, eax
|
||||
|
||||
call dword [.handler]
|
||||
|
||||
mov eax, gdt.user_data | 3
|
||||
mov ds, eax
|
||||
mov es, eax
|
||||
mov fs, eax
|
||||
mov eax, gdt.user_tls | 3
|
||||
mov gs, eax
|
||||
|
||||
add esp, 8 ; Skip interrupt code and reg pointer
|
||||
|
||||
pop eax
|
||||
pop ebx
|
||||
pop ecx
|
||||
pop edx
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebp
|
||||
|
||||
iretd
|
||||
|
||||
.handler: dd 0
|
||||
.entry: dd 0
|
||||
|
||||
idtr:
|
||||
dw (idt.end - idt) + 1
|
||||
dd idt
|
||||
|
||||
idt:
|
||||
%assign i 0
|
||||
|
||||
;Below system call
|
||||
%rep 128
|
||||
istruc IDTEntry
|
||||
at IDTEntry.offsetl, dw interrupts+(interrupts.second-interrupts.first)*i
|
||||
at IDTEntry.selector, dw gdt.kernel_code
|
||||
at IDTEntry.zero, db 0
|
||||
at IDTEntry.attribute, db attrib.present | attrib.interrupt32
|
||||
at IDTEntry.offseth, dw 0
|
||||
iend
|
||||
%assign i i+1
|
||||
%endrep
|
||||
|
||||
;System call
|
||||
istruc IDTEntry
|
||||
at IDTEntry.offsetl, dw interrupts+(interrupts.second-interrupts.first)*i
|
||||
at IDTEntry.selector, dw gdt.kernel_code
|
||||
at IDTEntry.zero, db 0
|
||||
at IDTEntry.attribute, db attrib.present | attrib.ring3 | attrib.interrupt32
|
||||
at IDTEntry.offseth, dw 0
|
||||
iend
|
||||
%assign i i+1
|
||||
|
||||
;Above system call
|
||||
%rep 127
|
||||
istruc IDTEntry
|
||||
at IDTEntry.offsetl, dw interrupts+(interrupts.second-interrupts.first)*i
|
||||
at IDTEntry.selector, dw gdt.kernel_code
|
||||
at IDTEntry.zero, db 0
|
||||
at IDTEntry.attribute, db attrib.present | attrib.interrupt32
|
||||
at IDTEntry.offseth, dw 0
|
||||
iend
|
||||
%assign i i+1
|
||||
%endrep
|
||||
.end:
|
|
@ -1,130 +0,0 @@
|
|||
struc IDTEntry
|
||||
.offsetl resw 1
|
||||
.selector resw 1
|
||||
.ist resb 1
|
||||
.attribute resb 1
|
||||
.offsetm resw 1
|
||||
.offseth resd 1
|
||||
.reserved resd 1
|
||||
endstruc
|
||||
|
||||
SECTION .text
|
||||
USE64
|
||||
interrupts:
|
||||
.first:
|
||||
mov [.entry], byte 0
|
||||
jmp qword .handle
|
||||
.second:
|
||||
%assign i 1
|
||||
%rep 255
|
||||
mov [.entry], byte i
|
||||
jmp qword .handle
|
||||
%assign i i+1
|
||||
%endrep
|
||||
.handle:
|
||||
push rbp
|
||||
push r15
|
||||
push r14
|
||||
push r13
|
||||
push r12
|
||||
push r11
|
||||
push r10
|
||||
push r9
|
||||
push r8
|
||||
push rsi
|
||||
push rdi
|
||||
push rdx
|
||||
push rcx
|
||||
push rbx
|
||||
push rax
|
||||
|
||||
mov rsi, rsp
|
||||
push rsi
|
||||
mov rdi, qword [.entry]
|
||||
push rdi
|
||||
|
||||
mov rax, gdt.kernel_data
|
||||
mov ds, rax
|
||||
mov es, rax
|
||||
mov fs, rax
|
||||
mov gs, rax
|
||||
|
||||
call qword [.handler]
|
||||
|
||||
mov rax, gdt.user_data | 3
|
||||
mov ds, rax
|
||||
mov es, rax
|
||||
mov gs, rax
|
||||
mov rax, gdt.user_tls | 3
|
||||
mov fs, rax
|
||||
|
||||
add rsp, 16 ; Skip interrupt code and reg pointer
|
||||
|
||||
pop rax
|
||||
pop rbx
|
||||
pop rcx
|
||||
pop rdx
|
||||
pop rdi
|
||||
pop rsi
|
||||
pop r8
|
||||
pop r9
|
||||
pop r10
|
||||
pop r11
|
||||
pop r12
|
||||
pop r13
|
||||
pop r14
|
||||
pop r15
|
||||
pop rbp
|
||||
|
||||
iretq
|
||||
|
||||
.handler: dq 0
|
||||
.entry: dq 0
|
||||
|
||||
idtr:
|
||||
dw (idt.end - idt) + 1
|
||||
dq idt
|
||||
|
||||
idt:
|
||||
%assign i 0
|
||||
|
||||
;Below syscall
|
||||
%rep 128
|
||||
istruc IDTEntry
|
||||
at IDTEntry.offsetl, dw interrupts+(interrupts.second-interrupts.first)*i
|
||||
at IDTEntry.selector, dw gdt.kernel_code
|
||||
at IDTEntry.ist, db 0
|
||||
at IDTEntry.attribute, db attrib.present | attrib.interrupt64
|
||||
at IDTEntry.offsetm, dw 0
|
||||
at IDTEntry.offseth, dd 0
|
||||
at IDTEntry.reserved, dd 0
|
||||
iend
|
||||
%assign i i+1
|
||||
%endrep
|
||||
|
||||
;Syscall
|
||||
istruc IDTEntry
|
||||
at IDTEntry.offsetl, dw interrupts+(interrupts.second-interrupts.first)*i
|
||||
at IDTEntry.selector, dw gdt.kernel_code
|
||||
at IDTEntry.ist, db 0
|
||||
at IDTEntry.attribute, db attrib.present | attrib.ring3 | attrib.interrupt64
|
||||
at IDTEntry.offsetm, dw 0
|
||||
at IDTEntry.offseth, dd 0
|
||||
at IDTEntry.reserved, dd 0
|
||||
iend
|
||||
%assign i i+1
|
||||
|
||||
;Above syscall
|
||||
%rep 127
|
||||
istruc IDTEntry
|
||||
at IDTEntry.offsetl, dw interrupts+(interrupts.second-interrupts.first)*i
|
||||
at IDTEntry.selector, dw gdt.kernel_code
|
||||
at IDTEntry.ist, db 0
|
||||
at IDTEntry.attribute, db attrib.present | attrib.interrupt64
|
||||
at IDTEntry.offsetm, dw 0
|
||||
at IDTEntry.offseth, dd 0
|
||||
at IDTEntry.reserved, dd 0
|
||||
iend
|
||||
%assign i i+1
|
||||
%endrep
|
||||
.end:
|
|
@ -146,5 +146,3 @@ tss:
|
|||
at TSS.iomap_base, dw 0xFFFF
|
||||
iend
|
||||
.end:
|
||||
|
||||
%include "interrupts-i386.asm"
|
||||
|
|
|
@ -73,11 +73,8 @@ long_mode:
|
|||
xor rax, rax
|
||||
mov eax, [kernel_base + 0x18]
|
||||
mov rbx, gdtr
|
||||
xchg bx, bx
|
||||
jmp rax
|
||||
.lp:
|
||||
sti
|
||||
hlt
|
||||
jmp .lp
|
||||
|
||||
gdtr:
|
||||
dw gdt.end + 1 ; size
|
||||
|
@ -179,5 +176,3 @@ long_mode:
|
|||
at TSS.iomap_base, dw 0xFFFF
|
||||
iend
|
||||
.end:
|
||||
|
||||
%include "interrupts-x86_64.asm"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue