Change bootConfig to bootParam since it makes more sense.
[SquirrelJME.git] / nanocoat / src / boot.c
blobf6716c9a876c12294f80da2b2564bcb033de75bd
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <string.h>
12 #include "sjme/boot.h"
13 #include "sjme/debug.h"
14 #include "sjme/nvm.h"
16 /**
17 * Combines all of the input ROMs and provides a virtual ROM that contains
18 * all of the libraries, this is so everything is within a single library
19 * set.
21 * @param config The input configuration.
22 * @param outLibraries The output libraries.
23 * @return If this was successful.
24 * @since 2023/07/28
26 static sjme_attrCheckReturn sjme_errorCode sjme_nvm_bootCombineRom(
27 sjme_attrInNotNull const sjme_nvm_bootParam* config,
28 sjme_attrOutNotNull sjme_static_libraries** outLibraries)
30 if (config == NULL || outLibraries == NULL)
31 return SJME_ERROR_NULL_ARGUMENTS;
33 /* Determine the total library count. */
34 if (SJME_JNI_TRUE)
35 sjme_todo("sjme_nvm_bootVirtualRom()");
37 /* Allocate output result. */
38 if (SJME_JNI_TRUE)
39 sjme_todo("sjme_nvm_bootVirtualRom()");
41 /* Bring in all the libraries into the output. */
42 if (SJME_JNI_TRUE)
43 sjme_todo("sjme_nvm_bootVirtualRom()");
45 /* Return the result. */
46 sjme_todo("sjme_nvm_bootVirtualRom()");
47 return SJME_ERROR_NOT_IMPLEMENTED;
50 sjme_errorCode sjme_nvm_boot(sjme_alloc_pool* mainPool,
51 const sjme_nvm_bootParam* param,
52 sjme_nvm_state** outState, int argc, char** argv)
54 sjme_nvm_state* result;
55 void* reservedBase;
56 sjme_alloc_pool* reservedPool;
57 sjme_jint reservedSize;
58 sjme_errorCode error;
60 if (param == NULL || outState == NULL)
61 return SJME_ERROR_NULL_ARGUMENTS;
63 /* Set up a reserved pool where all the data structures for the VM go... */
64 reservedBase = NULL;
65 reservedSize = 64 * 1024;
66 if (SJME_IS_ERROR(error = sjme_alloc(mainPool,
67 reservedSize, (void**)&reservedBase) ||
68 reservedBase == NULL))
69 return error;
71 /* Initialize a reserved pool where all of our own data structures go. */
72 reservedPool = NULL;
73 if (SJME_IS_ERROR(error = sjme_alloc_poolStatic(
74 &reservedPool, reservedBase, reservedSize)) ||
75 reservedPool == NULL)
76 return error;
78 /* Allocate resultant state. */
79 result = NULL;
80 if (SJME_IS_ERROR(error = sjme_alloc(reservedPool,
81 sizeof(*result), (void**)&result)) || result == NULL)
82 return error;
84 /* Set parameters accordingly. */
85 result->allocPool = mainPool;
86 result->reservedPool = reservedPool;
88 /* Copy the boot config over. */
89 memmove(&result->bootConfig, param, sizeof(*param));
91 /* Combine the input ROMs to a set of libraries. */
92 if (!sjme_nvm_bootCombineRom(param, &result->libraries))
94 sjme_nvm_destroy(result, NULL);
95 return SJME_JNI_FALSE;
98 /* Parse the command line arguments for options on running the VM. */
99 if (SJME_JNI_TRUE)
100 sjme_todo("sjme_nvm_boot()");
102 /* Spawn initial task which uses the main arguments. */
103 if (SJME_JNI_TRUE)
104 sjme_todo("sjme_nvm_boot()");
106 /* Return newly created VM. */
107 sjme_todo("sjme_nvm_boot()");
108 return SJME_ERROR_NOT_IMPLEMENTED;
111 sjme_errorCode sjme_nvm_destroy(sjme_nvm_state* state, sjme_jint* exitCode)
113 if (state == NULL)
114 return SJME_ERROR_NULL_ARGUMENTS;
116 /* Free sub-structures. */
117 if (SJME_JNI_TRUE)
118 sjme_todo("sjme_nvm_destroy()");
120 /* Free main structure. */
121 if (SJME_JNI_TRUE)
122 sjme_todo("sjme_nvm_destroy()");
124 /* Set exit code, if requested. */
125 if (SJME_JNI_TRUE)
126 sjme_todo("sjme_nvm_destroy()");
128 /* Finished. */
129 sjme_todo("sjme_nvm_destroy()");
130 return SJME_ERROR_NOT_IMPLEMENTED;