errors:
Code: Select all
Cannot export foo: symbol not found
...
What am I doing wrong here?
Code: Select all
Cannot export foo: symbol not found
...
Code: Select all
;----------------------------
global portCreate:function
align 0x10
portCreate:
mov eax,SYSCALL_PORT_CREATE
jmp [SYSCALL_CALL_ADDR]
;----------------------------
Code: Select all
#define SYSCALL_VADDR 0xBFFFF000
#define SYSCALL_TIMER_QUERY_COUNTER 10
uint64t timerQueryCounter() __attribute__((naked));
uint64t timerQueryCounter() {
uint64t res;
asm volatile("jmp (%[addr])"
:"=A"(res)
:"a" (SYSCALL_TIMER_QUERY_COUNTER), [addr] "m"(*(uint32t *)SYSCALL_VADDR));
return res;
}
Code: Select all
jmp dword[SYSCALL_VADDR]
Code: Select all
uint64t timerQueryCounter() {
uint64t res;
asm volatile("call (%[addr])"
:"=A"(res)
:"a" (SYSCALL_TIMER_QUERY_COUNTER), [addr] "i"(SYSCALL_VADDR));
return res;
}
Code: Select all
uint64t timerQueryCounter() {
uint64t res;
asm volatile("call *%[addr]"
:"=A"(res)
:"a" (SYSCALL_TIMER_QUERY_COUNTER), [addr] "m"(*((uint32t *)SYSCALL_VADDR)));
return res;
}
Try putting the attribute declaration after the function definition (ie, before the opening '{'). I think it's meant to go there - the callee creates its own stack frame, the caller doesn't care.FlashBurn wrote:So now I´m able to call my syscall stub, but I can´t get gcc to not create a stack frame.
I'm saying that, instead of this (from your earlier post):FlashBurn wrote:Sorry, but I didn´t understand a word from what you were saying
Code: Select all
uint64t timerQueryCounter() __attribute__((naked));
uint64t timerQueryCounter() {
...
}
Code: Select all
uint64t timerQueryCounter() __attribute__((naked)) {
...
}
Just be aware that that option applies to *all* functions (apart from the ones that need it for some other purpose) and disables backtraces, which is a pain if you need to do any kind of debugging.FlashBurn wrote:I found the flag for disable the creating of stack frames (but I thought that this flag is enabled at all O-Levels), its "-fomit-frame-pointer".
You can directly translate your code to a macro (this is GCC-specific; look up "statement exprs" in the GCC info page or the online manual)FlashBurn wrote:So I just need to find out how to create a macro so that I can inline the functions and the compiler push the parameters to the stack.
Code: Select all
#define timerQueryCounter() ({ uint64_t res; asm volatile (...); res; })
I think __attribute__ ((noreturn)) does the same thing (but more descriptively) and is used for functions like exit()FlashBurn wrote:And now I found a builtin (only for gcc >= 4.5.0) __builtin_unreachable which I can use so that the compiler knows that I´m not returning from my asm statement.
This wont work, because gcc only let you define attributes for functions when you declare them (I got an error as I tried it to do so). As I said, "naked" isn´t an attribute for x86 (it´s only for arm and some other cpus).Selenic wrote: You should have this:
(in fact, if you put declarations immediately above definitions like you had before, they're totally redundant. They're only useful in headers (for obvious reasons) and for declaring functions at the top of a file but defining them at the end, after functions which call them (depends on your style))Code: Select all
uint64t timerQueryCounter() __attribute__((naked)) { ... }
Nope. The problem is the asm statement. GCC doesn´t know that I´m not returning from it and assumes that the function does return and the other problem is that I have functions which return a value and there "noreturn" also doesn´t work. The macro also wont work, because I need that the parameters are pushed onto the stack.Selenic wrote: I think __attribute__ ((noreturn)) does the same thing (but more descriptively) and is used for functions like exit()