No, the array is a global variable in a .c file.
If I move the entire array to a function then it works fine even without "static" or "const"
Code: Select all
unsigned char FetchAndAnalyzeScancode()
{
unsigned char keymap[128] = { /* keys */};
// print char works fine ..
}
I found another strange behavior in my second stage bootloader. After I jumped to protected mode I print a small debug message (stored in .text section) to screen, clear the screen and jump to the C main function. That's works very well. But now I tried to move the debug message to .data section. After that nothing will be printed to the screen.
If I change the bootloader that the C main fuction won't be called again everything works well.
Works -> entire C main wasn't linked in the kernel:
Code: Select all
section .text
[BITS 32]
;[extern main] ; c main
ProtectedMode:
.main:
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
xor eax, eax
mov fs, ax
mov gs, ax
mov esp, 0x200000 ; set stack below 2 MB limit
call clrscr_32
mov esi, runningProtectedMode
call PutStr_32 ; <-- Print debug message - works
; dont jump to c main
;call main
jmp $
PutStr_32:
mov edi, [PutStr_Ptr]
.nextchar:
lodsb
test al, al
jz .end
stosw
jmp .nextchar
.end:
mov [PutStr_Ptr], edi
ret
clrscr_32:
mov edi, 0xb8000
mov [PutStr_Ptr], edi
mov ecx, 40 * 25
mov eax, 0x07200720 ; two times: 0x07 => white text & black background 0x20 => Space
rep stosd
ret
section .data
PutStr_Ptr dd 0xb8000
runningProtectedMode db "Running in 32 Bit ..", 0 ; <-- Debug Message
won't work -> entire C main linked in the kernel:
Code: Select all
section .text
[BITS 32]
;[extern main] ; c main
ProtectedMode:
.main:
mov ax, 0x10
mov ds, ax
mov ss, ax
mov es, ax
xor eax, eax
mov fs, ax
mov gs, ax
mov esp, 0x200000 ; set stack below 2 MB limit
call clrscr_32
mov esi, runningProtectedMode
call PutStr_32 <-- print debug message - won't work
; jump to c main
call main
jmp $
PutStr_32:
mov edi, [PutStr_Ptr]
.nextchar:
lodsb
test al, al
jz .end
stosw
jmp .nextchar
.end:
mov [PutStr_Ptr], edi
ret
clrscr_32:
mov edi, 0xb8000
mov [PutStr_Ptr], edi
mov ecx, 40 * 25
mov eax, 0x07200720 ; two times: 0x07 => white text & black background 0x20 => Space
rep stosd
ret
section .data
PutStr_Ptr dd 0xb8000
runningProtectedMode db "Running in 32 Bit ..", 0 ; <-- Debug Message
Therefore I think there is a problem in my linker script