I've got my own toolchain built with binutils, gcc, and newlib. In newlib I've created a very basic syscalls.c as described in the wiki. The only calls that are really sort of implemented are write() and _exit().
write() seems to be working now -- I'm able to output to my console from a program. However I'm having a problem with _exit()... although it's before _exit() is actually called, when exit() is working. exit() is either called explicitly by my code or implicitly after main() returns, because _start consists of calling main then exit (I believe this is coming from crt0.o provided by GCC, yes?).
The problem appears to be that sometime during exit(), before _exit() is called, a call is being made to an invalid pointer, or something. I get a general protection fault exception, at which point EIP is set to 0x00000001, which is not valid for my OS (user code starts at 0x80000000).
This is what exit() looks like in newlib:
Code: Select all
/*
* Exit, flushing stdio buffers if necessary.
*/
void
_DEFUN (exit, (code),
int code)
{
__call_exitprocs (code, NULL);
if (_GLOBAL_REENT->__cleanup)
(*_GLOBAL_REENT->__cleanup) (_GLOBAL_REENT);
_exit (code);
}
Code: Select all
exceptions.c:isr_13:330: EXCEPTION: General Protection Exception (Triple Fault), 00000000
exceptions.c:dump_registers:108: EAX=FFFFFFFF EBX=00000000 ECX=00010000 EDX=00010000
exceptions.c:dump_registers:109: EIP=00000001 ESP(k)=00236FE4 EBP=DFFFFFB8 ESP(u)=DFFFFFA0
exceptions.c:dump_registers:110: EDI=0 ESI=00000000
exceptions.c:dump_registers:111: CS=0000001B SS=00000023 DS=00000023 ES=00000023 FS=00000023 GS=00000023
exceptions.c:dump_stack:116: User Stack dump:
exceptions.c:dump_stack:157: DFFFFFA0 Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFA4 Argument: 00000000 (0)
exceptions.c:dump_stack:141: DFFFFFA8 Return address: 80007260
exceptions.c:dump_stack:145: DFFFFFAC Argument: DFFFFFCC (pointer to stack)
exceptions.c:dump_stack:157: DFFFFFB0 Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFB4 Argument: 00000000 (0)
exceptions.c:dump_stack:145: DFFFFFB8 Argument: DFFFFFD8 (pointer to stack)
exceptions.c:dump_stack:141: DFFFFFBC Return address: 80000174
exceptions.c:dump_stack:157: DFFFFFC0 Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFC4 Argument: 00000001 (1)
exceptions.c:dump_stack:145: DFFFFFC8 Argument: DFFFFFFC (pointer to stack)
exceptions.c:dump_stack:157: DFFFFFCC Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFD0 Argument: 00200034 (2097204)
exceptions.c:dump_stack:145: DFFFFFD4 Argument: DFFFFFE4 (pointer to stack)
exceptions.c:dump_stack:157: DFFFFFD8 Argument: 00000000 (0)
exceptions.c:dump_stack:141: DFFFFFDC Return address: 80000085
exceptions.c:dump_stack:141: DFFFFFE0 Return address: 80000085
exceptions.c:dump_stack:157: DFFFFFE4 Argument: 00000001 (1)
exceptions.c:dump_stack:145: DFFFFFE8 Argument: DFFFFFFC (pointer to stack)
exceptions.c:dump_stack:157: DFFFFFEC Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFF0 Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFF4 Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFF8 Argument: 00000000 (0)
exceptions.c:dump_stack:157: DFFFFFFC Argument: 5B00005F (1526726751)
exceptions.c:dump_stack:163: Dump complete.
process.c:end_current_thread:459: Ending thread 002148CC
Let me know if there's any additional info I can provide that might help diagnose this. I've been suck on it for a little while, and I'm a little bit mystified. I previously had a problem that turned out to be related to not setting up the stack properly (with command line args etc) at startup. I believe I'm doing that alright now (you can see it at the beginning of the stack), but maybe that's still a bit wrong or something. Or maybe this is occurring because I haven't fully implemented one of the syscalls.c functions. I really don't know
Thanks very much in advance for any insight you can provide!