I decided that I should adapt my OS to work in long mode (64 bits), before it grows more and becomes more complicated (I don't want to regret it later). The bootloader works well, now I try to port the IDT (which in part is written in assembly, 50% C and 50% NASM) I'm just getting troubles in assembly (I'm not very good at assembly)
I already changed the IDT structure to the AMD64 one
Code: Select all
idt.inc:320: error: instruction not supported in 64-bit mode
idt.inc:321: error: instruction not supported in 64-bit mode
idt.inc:336: error: instruction not supported in 64-bit mode
idt.inc:337: error: instruction not supported in 64-bit mode
idt.inc:475: error: instruction not supported in 64-bit mode
idt.inc:476: error: instruction not supported in 64-bit mode
idt.inc:494: error: instruction not supported in 64-bit mode
idt.inc:495: error: instruction not supported in 64-bit mode
Code: Select all
global idt_load
extern fault_handler
extern idtp
extern kputs
extern k_readkb
extern getch
extern cmd_shell
; Loads the IDT defined in '_idtp' into the processor.
idt_load:
lidt [idtp]
ret
global isr0
global isr1
global isr2
global isr3
global isr4
global isr5
global isr6
global isr7
global isr8
global isr9
global isr10
global isr11
global isr12
global isr13
global isr14
global isr15
global isr16
global isr17
global isr18
global isr19
global isr20
global isr21
global isr22
global isr23
global isr24
global isr25
global isr26
global isr27
global isr28
global isr29
global isr30
global isr31
global isr128
%macro pushall 0
push rax
push rcx
push rdx
push rbx
push rbp
push rsi
push rdi
%endmacro
%macro popall 0
pop rax
pop rcx
pop rdx
pop rbx
pop rbp
pop rsi
pop rdi
%endmacro
isr0:
cli
push byte 0
push byte 0
jmp isr_common_stub
isr1:
cli
push byte 0
push byte 1
jmp isr_common_stub
isr2:
cli
push byte 0
push byte 2
jmp isr_common_stub
isr3:
cli
push byte 0
push byte 3
jmp isr_common_stub
isr4:
cli
push byte 0
push byte 4
jmp isr_common_stub
isr5:
cli
push byte 0
push byte 5
jmp isr_common_stub
isr6:
cli
push byte 0
push byte 6
jmp isr_common_stub
isr7:
cli
push byte 0
push byte 7
jmp isr_common_stub
isr8:
cli
push byte 8
jmp isr_common_stub
isr9:
cli
push byte 0
push byte 9
jmp isr_common_stub
isr10:
cli
push byte 10
jmp isr_common_stub
isr11:
cli
push byte 11
jmp isr_common_stub
isr12:
cli
push byte 12
jmp isr_common_stub
isr13:
cli
push byte 13
jmp isr_common_stub
isr14:
cli
push byte 14
jmp isr_common_stub
isr15:
cli
push byte 0
push byte 15
jmp isr_common_stub
isr16:
cli
push byte 0
push byte 16
jmp isr_common_stub
isr17:
cli
push byte 0
push byte 18
jmp isr_common_stub
isr18:
cli
push byte 0
push byte 18
jmp isr_common_stub
isr19:
cli
push byte 0
push byte 19
jmp isr_common_stub
isr20:
cli
push byte 0
push byte 20
jmp isr_common_stub
isr21:
cli
push byte 0
push byte 21
jmp isr_common_stub
isr22:
cli
push byte 0
push byte 22
jmp isr_common_stub
isr23:
cli
push byte 0
push byte 23
jmp isr_common_stub
isr24:
cli
push byte 0
push byte 24
jmp isr_common_stub
isr25:
cli
push byte 0
push byte 25
jmp isr_common_stub
isr26:
cli
push byte 0
push byte 26
jmp isr_common_stub
isr27:
cli
push byte 0
push byte 26
jmp isr_common_stub
isr28:
cli
push byte 0
push byte 28
jmp isr_common_stub
isr29:
cli
push byte 0
push byte 29
jmp isr_common_stub
isr30:
cli
push byte 0
push byte 30
jmp isr_common_stub
isr31:
cli
push byte 0
push byte 31
jmp isr_common_stub
; Int 80h
; Registers:
; eax = service, ecx
isr128:
cli
push byte 0
push byte 80
cmp rax, 1 ; Service 1 (terminate program)
je .terminate_prg
cmp rax, 3 ; Service 3 (read keyboard)
je .read_srv
cmp rax, 4 ; Service 4 (prints text)
je .write_srv
jmp .end
.terminate_prg:
; We don't have processes yet, because we still in
; monotasking. Just return to the command shell
call cmd_shell
jmp isr_common_stub
jmp .end
.read_srv:
xor rax, rax
push rdx
push rcx
call k_readkb
pop rdx
pop rcx
jmp isr_common_stub
jmp .end
.write_srv:
xor rax, rax
push rcx
call kputs
pop rcx
jmp isr_common_stub
.end:
isr_common_stub:
pushall
push ds
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov rax, rsp
push rax
mov rax, fault_handler
call rax
pop rax
pop gs
pop fs
pop es
pop ds
popall
add rsp, 8
iretq
global irq0
global irq1
global irq2
global irq3
global irq4
global irq5
global irq6
global irq7
global irq8
global irq9
global irq10
global irq11
global irq12
global irq13
global irq14
global irq15
; 32: IRQ0
irq0:
cli
push byte 0
push byte 32
jmp irq_common_stub
; 33: IRQ1
irq1:
cli
push byte 0
push byte 33
jmp irq_common_stub
; 34: IRQ2
irq2:
cli
push byte 0
push byte 34
jmp irq_common_stub
; 35: IRQ3
irq3:
cli
push byte 0
push byte 35
jmp irq_common_stub
; 36: IRQ4
irq4:
cli
push byte 0
push byte 36
jmp irq_common_stub
; 37: IRQ5
irq5:
cli
push byte 0
push byte 37
jmp irq_common_stub
; 38: IRQ6
irq6:
cli
push byte 0
push byte 38
jmp irq_common_stub
; 39: IRQ7
irq7:
cli
push byte 0
push byte 39
jmp irq_common_stub
; 40: IRQ8
irq8:
cli
push byte 0
push byte 40
jmp irq_common_stub
; 41: IRQ9
irq9:
cli
push byte 0
push byte 41
jmp irq_common_stub
; 42: IRQ10
irq10:
cli
push byte 0
push byte 42
jmp irq_common_stub
; 43: IRQ11
irq11:
cli
push byte 0
push byte 43
jmp irq_common_stub
; 44: IRQ12
irq12:
cli
push byte 0
push byte 44
jmp irq_common_stub
; 45: IRQ13
irq13:
cli
push byte 0
push byte 45
jmp irq_common_stub
; 46: IRQ14
irq14:
cli
push byte 0
push byte 46
jmp irq_common_stub
; 47: IRQ15
irq15:
cli
push byte 0
push byte 47
jmp irq_common_stub
extern irq_handler
irq_common_stub:
pushall
push ds ; Can't push segment register directly in x64
push es
push fs
push gs
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov rax, rsp
push rax
mov rax, irq_handler
call rax
pop rax
pop gs
pop fs
pop es
pop ds
popall
add rsp, 8
iretq
Porting this is more than just replacing "e" with "r".
Thank for you patience.