// File: /workspace/github_cpp_makefile_star2_O2/sykeben[P]overos/os/kernel.cpp
// Function: main
int main(int argc, char** argv) {
	// This is the "kernel" for overOS.
	// It really isn't a kernel, but whatever.
	
	// Prepare kernel enviroment.
	cout << "Kernel started, getting ready..." << _TERM;
	#ifdef _WIN32
		if (fexists(".\\os\\kautorun.exe")) system(".\\os\\kautorun");
	#else
		if (fexists("./os/kautorun")) system("./os/kautorun");
	#endif
	settitle("OverOS Shell");
	
	// Let the user know the kernel & shell are ready.
	clear_screen();
	cout << "[ OverOS " << _VMAJOR << '.' << _VMINOR << '.' << _VREVISION << " Shell ]" << _TERM;
	cout << "Run \"help\" for assistance." << _TERM;
	
	while (!_EXIT) {
		
		// Get user command input.
		if (_CLEARED) _CLEARED = false; else cout << _TERM;
		cout << "~> ";
		cin.getline(_INPUT, _MAXIN, _TERM);
		
		// Internal commands & externel executor.
		if (!strcmp(_INPUT, "help")) {
			// Help //
			cout << "Internal shell commands: help exitnow clr sysver listcmds" << _TERM;
			cout << "The prompt may also run executables from the \\cmd directory." << _TERM;
		} else if (!strcmp(_INPUT, "exitnow")) {
			// ExitNow //
			cout << "Exiting OverOS now..." << _TERM;
			_EXIT = true; _EXITCODE = 0;
		} else if (!strcmp(_INPUT, "clr")) {
			// Clr //
			clear_screen(); _CLEARED = true;
		} else if (!strcmp(_INPUT, "sysver")) {
			// SysVer //
			cout << "OverOS System Version " << _VMAJOR << '.' << _VMINOR << '.' << _VREVISION << _TERM;
		} else if (!strcmp(_INPUT, "listcmds")) {
			// ListCmds //
			cout << "Files in the \\cmd directory:" << _TERM;
			system(_LISTCMDS.c_str());
		} else {
			// Externel Executor //
			_INPUTSTR = _INPUT;
			#ifdef _WIN32
				_CMDF = ".\\cmd\\" + _INPUTSTR.substr(0, _INPUTSTR.find(' '));
				_CMDF += ".exe";
			#else
				_CMDF = "./cmd/" + _INPUTSTR.substr(0, _INPUTSTR.find(' '));
			#endif
			_CMDFWIN = _CMDF + ".exe";
			if (fexists(_CMDF) || fexists(_CMDFWIN)) {
				#ifdef _WIN32
					system((".\\cmd\\" + _INPUTSTR).c_str());
				#else
					system(("./cmd/" + _INPUTSTR).c_str());
				#endif
			} else {
				// Invalid Error //
				cout << "Error: Invalid command, " << _INPUT << "." << _TERM;
			}
		}
	}
	
	return _EXITCODE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq 0x2b0a(%rip), %rdi      # 0x4fd0
leaq 0xb5d(%rip), %rsi       # 0x302a
callq 0x20a0
pushq $0xa
popq %rsi
movq %rax, %rdi
callq 0x20e0
leaq 0xb67(%rip), %rsi       # 0x304b
leaq -0x48(%rbp), %rbx
leaq -0x88(%rbp), %rdx
movq %rbx, %rdi
callq 0x2928
movq %rbx, %rdi
callq 0x247c
movl %eax, %r14d
movq %rbx, %rdi
callq 0x21d8
testb %r14b, %r14b
je 0x251b
leaq 0xb35(%rip), %rdi       # 0x304b
callq 0x2080
leaq 0xb37(%rip), %rsi       # 0x3059
leaq -0x68(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x2928
leaq -0x68(%rbp), %rdi
callq 0x240d
leaq -0x68(%rbp), %rdi
callq 0x21d8
callq 0x23fc
movq 0x2a83(%rip), %rbx      # 0x4fd0
leaq 0xb12(%rip), %rsi       # 0x3066
movq %rbx, %rdi
callq 0x20a0
movl 0x2bc2(%rip), %esi      # 0x5124
movq %rax, %rdi
callq 0x2160
pushq $0x2e
popq %r14
movq %rax, %rdi
movl %r14d, %esi
callq 0x20e0
movl 0x2b79(%rip), %esi      # 0x50f8
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
movl %r14d, %esi
callq 0x20e0
movl 0x2b64(%rip), %esi      # 0x50fc
movq %rax, %rdi
callq 0x2160
leaq 0xac9(%rip), %rsi       # 0x3070
movq %rax, %rdi
callq 0x20a0
pushq $0xa
popq %r15
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
leaq 0xab4(%rip), %rsi       # 0x3079
movq %rbx, %rdi
callq 0x20a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
leaq 0xab5(%rip), %r12       # 0x3094
movq 0x29fa(%rip), %r13      # 0x4fe0
leaq 0x2b53(%rip), %r14      # 0x5140
cmpb $0x0, 0x2b34(%rip)      # 0x5128
jne 0x28e4
cmpb $0x1, 0x2b2f(%rip)      # 0x5130
jne 0x260c
movb $0x0, 0x2b26(%rip)      # 0x5130
jmp 0x2617
movq %rbx, %rdi
movl %r15d, %esi
callq 0x20e0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x20a0
movl $0xff, %edx
movq %r13, %rdi
movq %r14, %rsi
movl %r15d, %ecx
callq 0x21b0
movq %r14, %rdi
leaq 0xa59(%rip), %rsi       # 0x3098
pushq $0x5
popq %rdx
callq 0x20c0
testl %eax, %eax
je 0x268e
movq 0x2aee(%rip), %rax      # 0x5140
movabsq $0x776f6e74697865, %rcx # imm = 0x776F6E74697865
cmpq %rcx, %rax
jne 0x26c7
movq %rbx, %rdi
leaq 0xaa9(%rip), %rsi       # 0x3114
callq 0x20a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
movb $0x1, 0x2aa6(%rip)      # 0x5128
andl $0x0, 0x2aa3(%rip)      # 0x512c
jmp 0x25ed
movq %rbx, %rdi
leaq 0xa05(%rip), %rsi       # 0x309d
callq 0x20a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
movq %rbx, %rdi
leaq 0xa25(%rip), %rsi       # 0x30d7
callq 0x20a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
jmp 0x25ed
cmpl $0x726c63, %eax         # imm = 0x726C63
jne 0x26df
callq 0x23fc
movb $0x1, 0x2a56(%rip)      # 0x5130
jmp 0x25ed
movq %r14, %rdi
leaq 0xa41(%rip), %rsi       # 0x312a
pushq $0x7
popq %rdx
callq 0x20c0
testl %eax, %eax
je 0x280b
movq %r14, %rdi
leaq 0x9cb(%rip), %rsi       # 0x30ce
pushq $0x9
popq %rdx
callq 0x20c0
testl %eax, %eax
je 0x286b
leaq 0x2b26(%rip), %r12      # 0x5240
movq %r12, %rdi
movq %r14, %rsi
callq 0x21a0
movq %r12, %rdi
pushq $0x20
popq %rsi
xorl %edx, %edx
callq 0x2120
leaq -0x88(%rbp), %rdi
movq %r12, %rsi
movq %rdi, %r12
xorl %edx, %edx
movq %rax, %rcx
callq 0x20d0
leaq -0x48(%rbp), %r13
movq %r13, %rdi
leaq 0xa0e(%rip), %rsi       # 0x3165
movq %r12, %rdx
callq 0x2963
leaq 0x2afa(%rip), %rdi      # 0x5260
movq %r13, %rsi
callq 0x2100
movq %r13, %rdi
callq 0x21d8
movq %r12, %rdi
callq 0x21d8
movq %r13, %rdi
leaq 0x2ad8(%rip), %rsi      # 0x5260
leaq 0x9dd(%rip), %rdx       # 0x316c
callq 0x2991
leaq 0x2ae5(%rip), %rdi      # 0x5280
movq %r13, %rsi
callq 0x2100
movq %r13, %rdi
callq 0x21d8
leaq 0x2aae(%rip), %rdi      # 0x5260
callq 0x247c
testb %al, %al
leaq 0x8d4(%rip), %r12       # 0x3094
jne 0x27d6
leaq 0x2ab7(%rip), %rdi      # 0x5280
callq 0x247c
testb %al, %al
je 0x28a4
leaq -0x48(%rbp), %rdi
leaq 0x984(%rip), %rsi       # 0x3165
leaq 0x2a58(%rip), %rdx      # 0x5240
callq 0x29c9
movq -0x48(%rbp), %rdi
callq 0x2080
movq 0x27e3(%rip), %r13      # 0x4fe0
leaq -0x48(%rbp), %rdi
callq 0x21d8
jmp 0x25ed
movq %rbx, %rdi
leaq 0x91c(%rip), %rsi       # 0x3131
callq 0x20a0
movl 0x2904(%rip), %esi      # 0x5124
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
pushq $0x2e
popq %r12
movl %r12d, %esi
callq 0x20e0
movl 0x28bb(%rip), %esi      # 0x50f8
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
movl %r12d, %esi
callq 0x20e0
movl 0x28a6(%rip), %esi      # 0x50fc
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
jmp 0x2891
movq %rbx, %rdi
leaq 0x8d3(%rip), %rsi       # 0x3148
callq 0x20a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
movq 0x2a34(%rip), %rdi      # 0x52c0
callq 0x2080
leaq 0x7fc(%rip), %r12       # 0x3094
movq 0x2741(%rip), %r13      # 0x4fe0
jmp 0x25ed
movq %rbx, %rdi
leaq 0x8c3(%rip), %rsi       # 0x3171
callq 0x20a0
movq %rax, %rdi
movq %r14, %rsi
callq 0x20a0
movq %rax, %rdi
leaq 0x860(%rip), %rsi       # 0x3128
callq 0x20a0
movq %rax, %rdi
movl %r15d, %esi
callq 0x20e0
movq 0x2701(%rip), %r13      # 0x4fe0
jmp 0x25ed
movl 0x2842(%rip), %eax      # 0x512c
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
jmp 0x291a
movq %rax, %rbx
jmp 0x291f
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
jmp 0x291a
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x21d8
movq %rbx, %rdi
callq 0x2170
nop