mkfree wrote:when you assembled the springboard code you told the compiler which will assemble at address 0x80000 ?
nullplan wrote:For this reason, I am using a pretty much self-contained trampoline
Now I solved my problem. As I understood from your two replies, I forgot to rebase the physical addresses to be available for the AP CPUs in the trampoline code. My working trampoline code now looks something like this:
Code: Select all
%define REBASE(ADDR) (ADDR - ap_cpu_trampoline_code + 0x7000)
%define REBASE32(ADDR) (ADDR - mp_32_start + 0x8000)
extern printk
extern gdt_pointer
extern idt_pointer
ap_cpu_trampoline_code:
[BITS 16]
cli
mov eax, cr0
or eax, 0x1
mov cr0, eax
;a32 lidt [REBASE(idt16_ptr)]
a32 lgdt [REBASE(gdt16_ptr)]
jmp 0x18:0x8000
gdt16_base: ; GDT descriptor table
.null: ; 0x00 - null segment descriptor
dd 0x00000000 ; must be left zero'd
dd 0x00000000 ; must be left zero'd
.code32: ; 0x01 - 32bit code segment descriptor 0xFFFFFFFF
dw 0xFFFF ; limit 0:15
dw 0x0000 ; base 0:15
db 0x00 ; base 16:23
db 0x9A ; present, iopl/0, code, execute/read
db 0xCF ; 4Kbyte granularity, 32bit selector; limit 16:19
db 0x00 ; base 24:31
.data32: ; 0x02 - 32bit data segment descriptor 0xFFFFFFFF
dw 0xFFFF ; limit 0:15
dw 0x0000 ; base 0:15
db 0x00 ; base 16:23
db 0x92 ; present, iopl/0, data, read/write
db 0xCF ; 4Kbyte granularity, 32bit selector; limit 16:19
db 0x00 ; base 24:31
.code16: ; 0x03 - 16bit code segment descriptor 0x000FFFFF
dw 0xFFFF ; limit 0:15
dw 0x0000 ; base 0:15
db 0x00 ; base 16:23
db 0x9A ; present, iopl/0, code, execute/read
db 0x0F ; 1Byte granularity, 16bit selector; limit 16:19
db 0x00 ; base 24:31
.data16: ; 0x04 - 16bit data segment descriptor 0x000FFFFF
dw 0xFFFF ; limit 0:15
dw 0x0000 ; base 0:15
db 0x00 ; base 16:23
db 0x92 ; present, iopl/0, data, read/write
db 0x0F ; 1Byte granularity, 16bit selector; limit 16:19
db 0x00 ; base 24:31
gdt16_ptr: ; GDT table pointer for 16bit access
dw gdt16_ptr - gdt16_base - 1 ; table limit (size)
dd gdt16_base ; table base address
idt16_ptr: ; IDT table pointer for 16bit access
dw 0x03FF ; table limit (size)
dd 0x00000000 ; table base address
trampoline_end:
mp_32_start:
jmp 0x08:REBASE32(next)
[BITS 32]
next:
; --- to make sure ------> enable A20
in al, 0x92
or al, 2
out 0x92, al
mov esp, @mp_stack
mov ax, 0x10
mov ds, ax
mov es, ax
mov ss, ax
mov fs, ax
mov gs, ax
;mov eax, 0xB8000
;mov BYTE [eax], 'O'
;add eax, 1
;mov BYTE [eax], 0x0F
;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <---- PROBLEM HERE
push hello_message
call printk
;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++ <---- PROBLEM HERE
hlt
mp_32_end:
section .bss
space resb 4096
@mp_stack
section .data
hello_message: db "Hello from mp", 0
It works fine and prints expected letter to the screen, but any call to the specified
extern functions (e.g.
printk in my above mentioned code) will be resulted into a triple fault and rebooting.
- I had the suspicion that A20 line can solve the problem, but it did not help (here is the code for A20 activation through port 0x92 but I also tried the activation via keyboard).
- even doing
Code: Select all
xor ax, ax
mov ds, ax
lgdt [gdt_pointer]
lidt [idt_pointer]
right after
mov esp, @pm_stackwill be resulted to triple fault. Both idt_pointer and gdt_pointer are the BSP kernel pointers.
- Even if I call the physical address of printk instead of its extern label, the same problem occurs (and true for idt_pointer and gdt_pointer).
What did I do wrong?
Best.
Iman.