libn64/os: Push the idle thread into assembly.
authorTyler J. Stachecki <stachecki.tyler@gmail.com>
Thu, 21 Sep 2017 01:57:06 +0000 (21:57 -0400)
committerTyler J. Stachecki <stachecki.tyler@gmail.com>
Thu, 21 Sep 2017 03:00:55 +0000 (23:00 -0400)
Signed-off-by: Tyler J. Stachecki <stachecki.tyler@gmail.com>
libn64/Makefile
libn64/os/asm/idle_thread.s [new file with mode: 0644]
libn64/os/idle_thread.c [deleted file]
libn64/os/main.c

index 88bb894..4fcc909 100644 (file)
@@ -29,13 +29,13 @@ ASMFILES = $(call FIXPATH,\
        os/asm/boot.s \
        os/asm/context.s \
        os/asm/exception.s \
+       os/asm/idle_thread.s \
        os/asm/message.s \
        os/asm/syscall.s \
 )
 
 CFILES = $(call FIXPATH,\
        os/fbtext.c \
-       os/idle_thread.c \
        os/main.c \
        os/mm.c \
        os/panic.c \
diff --git a/libn64/os/asm/idle_thread.s b/libn64/os/asm/idle_thread.s
new file mode 100644 (file)
index 0000000..12a928d
--- /dev/null
@@ -0,0 +1,41 @@
+#
+# libn64/os/asm/idle_thread.s: libn64 idle thread.
+#
+# n64chain: A (free) open-source N64 development toolchain.
+# Copyright 2014-16 Tyler J. Stachecki <stachecki.tyler@gmail.com>
+#
+# This file is subject to the terms and conditions defined in
+# 'LICENSE', which is part of this source code package.
+#
+
+#include <libn64.h>
+
+.section .text.libn64.ipl, "ax", @progbits
+
+.set noat
+.set gp=64
+.set noreorder
+
+# -------------------------------------------------------------------
+#  This thread invokes main and then spins continuously.
+# -------------------------------------------------------------------
+.global libn64_idle_thread
+.type libn64_idle_thread, @function
+.align 5
+libn64_idle_thread:
+  la $a0, main
+  xor $a1, $a1, $a2
+  addiu $a2, $zero, 0x1
+  xor $at, $at, $at
+  syscall
+
+libn64_idle_thread_spin:
+  j libn64_idle_thread_spin
+  nop
+
+.size libn64_idle_thread,.-libn64_idle_thread
+
+.set at
+.set gp=default
+.set reorder
+
diff --git a/libn64/os/idle_thread.c b/libn64/os/idle_thread.c
deleted file mode 100644 (file)
index 0d2a2b4..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-//
-// libn64/os/idle_thread.c: libn64 idle thread.
-//
-// n64chain: A (free) open-source N64 development toolchain.
-// Copyright 2014-16 Tyler J. Stachecki <stachecki.tyler@gmail.com>
-//
-// This file is subject to the terms and conditions defined in
-// 'LICENSE', which is part of this source code package.
-//
-
-#include <os/idle_thread.h>
-
-void libn64_idle_thread(void) {
-  while (1);
-  __builtin_unreachable();
-}
-
index 30d5536..1d29eb5 100644 (file)
@@ -25,10 +25,7 @@ void libn64_main(uint32_t kernel_sp, uint32_t bss_end) {
   // Put the given physical memory region under control of the MM.
   libn64_mm_init(bss_end, kernel_sp - 256);
 
-  // Hand control over to the application (in another thread).
-  libn64_thread_create(main, NULL, LIBN64_THREAD_MIN_PRIORITY + 1);
-
-  // This thread becomes the idle thread.
+  // This thread invokes main() and becomes the idle thread.
   libn64_idle_thread();
   __builtin_unreachable();
 }