// File: 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
subq $0x130, %rsp            # imm = 0x130
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x38c0(%rip), %rdi      # 0x5fd0
leaq 0x1913(%rip), %rsi      # 0x402a
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
leaq -0x31(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x22c0
movq -0xf8(%rbp), %rdx
leaq 0x1904(%rip), %rsi      # 0x404b
leaq -0x30(%rbp), %rdi
callq 0x2cc0
jmp 0x2752
leaq -0x30(%rbp), %rdi
callq 0x26a0
movb %al, -0xf9(%rbp)
jmp 0x2763
leaq -0x30(%rbp), %rdi
callq 0x2328
leaq -0x31(%rbp), %rdi
callq 0x21a0
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0x2781
jmp 0x27c0
leaq 0x18c3(%rip), %rdi      # 0x404b
callq 0x2130
jmp 0x27c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x27b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x2328
leaq -0x31(%rbp), %rdi
callq 0x21a0
jmp 0x2caa
leaq -0x69(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x22c0
movq -0x108(%rbp), %rdx
leaq 0x187b(%rip), %rsi      # 0x4059
leaq -0x68(%rbp), %rdi
callq 0x2cc0
jmp 0x27e9
leaq -0x68(%rbp), %rdi
callq 0x25e0
jmp 0x27f4
leaq -0x68(%rbp), %rdi
callq 0x2328
leaq -0x69(%rbp), %rdi
callq 0x21a0
callq 0x25c0
movq 0x37be(%rip), %rdi      # 0x5fd0
leaq 0x184d(%rip), %rsi      # 0x4066
callq 0x2160
movq %rax, %rdi
movl 0x399d(%rip), %esi      # 0x61c4
callq 0x22a0
movq %rax, %rdi
movl $0x2e, %esi
callq 0x21d0
movq %rax, %rdi
movl 0x395e(%rip), %esi      # 0x61a0
callq 0x22a0
movq %rax, %rdi
movl $0x2e, %esi
callq 0x21d0
movq %rax, %rdi
movl 0x3947(%rip), %esi      # 0x61a4
callq 0x22a0
movq %rax, %rdi
leaq 0x1804(%rip), %rsi      # 0x4070
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
movq 0x374b(%rip), %rdi      # 0x5fd0
leaq 0x17ed(%rip), %rsi      # 0x4079
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
movb 0x3924(%rip), %al       # 0x61c8
xorb $-0x1, %al
testb $0x1, %al
jne 0x28af
jmp 0x2c9b
testb $0x1, 0x391a(%rip)      # 0x61d0
je 0x28f2
movb $0x0, 0x3911(%rip)      # 0x61d0
jmp 0x2903
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x28e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x2328
leaq -0x69(%rbp), %rdi
callq 0x21a0
jmp 0x2caa
movq 0x36d7(%rip), %rdi      # 0x5fd0
movl $0xa, %esi
callq 0x21d0
movq 0x36c6(%rip), %rdi      # 0x5fd0
leaq 0x1783(%rip), %rsi      # 0x4094
callq 0x2160
movq 0x36c3(%rip), %rdi      # 0x5fe0
leaq 0x38bc(%rip), %rsi      # 0x61e0
movl $0xff, %edx
movl $0xa, %ecx
callq 0x22f0
leaq 0x38a6(%rip), %rdi      # 0x61e0
leaq 0x1757(%rip), %rsi      # 0x4098
callq 0x2240
cmpl $0x0, %eax
jne 0x2990
movq 0x367e(%rip), %rdi      # 0x5fd0
leaq 0x1744(%rip), %rsi      # 0x409d
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
movq 0x365e(%rip), %rdi      # 0x5fd0
leaq 0x175e(%rip), %rsi      # 0x40d7
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
jmp 0x2c96
leaq 0x3849(%rip), %rdi      # 0x61e0
leaq 0x1776(%rip), %rsi      # 0x4114
callq 0x2240
cmpl $0x0, %eax
jne 0x29de
movq 0x3621(%rip), %rdi      # 0x5fd0
leaq 0x1766(%rip), %rsi      # 0x411c
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
movb $0x1, 0x37f9(%rip)      # 0x61c8
movl $0x0, 0x37f3(%rip)      # 0x61cc
jmp 0x2c94
leaq 0x37fb(%rip), %rdi      # 0x61e0
leaq 0x1746(%rip), %rsi      # 0x4132
callq 0x2240
cmpl $0x0, %eax
jne 0x2a07
callq 0x25c0
movb $0x1, 0x37ce(%rip)      # 0x61d0
jmp 0x2c92
leaq 0x37d2(%rip), %rdi      # 0x61e0
leaq 0x1721(%rip), %rsi      # 0x4136
callq 0x2240
cmpl $0x0, %eax
jne 0x2a88
movq 0x35aa(%rip), %rdi      # 0x5fd0
leaq 0x1710(%rip), %rsi      # 0x413d
callq 0x2160
movq %rax, %rdi
movl 0x3789(%rip), %esi      # 0x61c4
callq 0x22a0
movq %rax, %rdi
movl $0x2e, %esi
callq 0x21d0
movq %rax, %rdi
movl 0x374a(%rip), %esi      # 0x61a0
callq 0x22a0
movq %rax, %rdi
movl $0x2e, %esi
callq 0x21d0
movq %rax, %rdi
movl 0x3733(%rip), %esi      # 0x61a4
callq 0x22a0
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
jmp 0x2c90
leaq 0x3751(%rip), %rdi      # 0x61e0
leaq 0x1638(%rip), %rsi      # 0x40ce
callq 0x2240
cmpl $0x0, %eax
jne 0x2ad9
movq 0x3529(%rip), %rdi      # 0x5fd0
leaq 0x16a6(%rip), %rsi      # 0x4154
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
leaq 0x3899(%rip), %rdi      # 0x6360
callq 0x2090
movq %rax, %rdi
callq 0x2130
jmp 0x2c8e
leaq 0x3800(%rip), %rdi      # 0x62e0
movq %rdi, -0x120(%rbp)
leaq 0x36f2(%rip), %rsi      # 0x61e0
callq 0x2220
movq -0x120(%rbp), %rdi
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x118(%rbp)
movl $0x20, %esi
callq 0x2210
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
movq %rax, %rcx
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x2180
movq -0x110(%rbp), %rdx
leaq 0x1630(%rip), %rsi      # 0x4171
leaq -0x90(%rbp), %rdi
callq 0x2d70
jmp 0x2b4f
leaq 0x37aa(%rip), %rdi      # 0x6300
leaq -0x90(%rbp), %rsi
callq 0x21f0
leaq -0x90(%rbp), %rdi
callq 0x2328
leaq -0xb0(%rbp), %rdi
callq 0x2328
leaq -0xd0(%rbp), %rdi
leaq 0x3778(%rip), %rsi      # 0x6300
leaq 0x15e9(%rip), %rdx      # 0x4178
callq 0x2dc0
leaq 0x3785(%rip), %rdi      # 0x6320
leaq -0xd0(%rbp), %rsi
callq 0x21f0
leaq -0xd0(%rbp), %rdi
callq 0x2328
leaq 0x3746(%rip), %rdi      # 0x6300
callq 0x26a0
testb $0x1, %al
jne 0x2bd5
leaq 0x3756(%rip), %rdi      # 0x6320
callq 0x26a0
testb $0x1, %al
jne 0x2bd5
jmp 0x2c4e
leaq 0x1595(%rip), %rsi      # 0x4171
leaq 0x36fd(%rip), %rdx      # 0x62e0
leaq -0xf0(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x2e40
movq -0x128(%rbp), %rdi
callq 0x2090
movq %rax, %rdi
callq 0x2130
jmp 0x2c0c
leaq -0xf0(%rbp), %rdi
callq 0x2328
jmp 0x2c8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x2328
jmp 0x2caa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2328
jmp 0x2caa
movq 0x337b(%rip), %rdi      # 0x5fd0
leaq 0x1521(%rip), %rsi      # 0x417d
callq 0x2160
movq %rax, %rdi
leaq 0x3575(%rip), %rsi      # 0x61e0
callq 0x2160
movq %rax, %rdi
leaq 0x14b6(%rip), %rsi      # 0x4130
callq 0x2160
movq %rax, %rdi
movl $0xa, %esi
callq 0x21d0
jmp 0x2c8e
jmp 0x2c90
jmp 0x2c92
jmp 0x2c94
jmp 0x2c96
jmp 0x289e
movl 0x352b(%rip), %eax      # 0x61cc
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x22b0
nopw %cs:(%rax,%rax)
nopl (%rax)