This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module.prototype.require = function(path) { | |
assert(path, 'missing path'); | |
assert(typeof path === 'string', 'path must be a string'); | |
return Module._load(path, this, /* isMain */ false); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Run the file contents in the correct scope or sandbox. Expose | |
// the correct helper variables (require, module, exports) to | |
// the file. | |
// Returns exception, if any. | |
Module.prototype._compile = function(content, filename) { | |
// Remove shebang | |
var contLen = content.length; | |
if (contLen >= 2) { | |
if (content.charCodeAt(0) === 35/*#*/ && | |
content.charCodeAt(1) === 33/*!*/) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Check the cache for the requested file. | |
// 1. If a module already exists in the cache: return its exports object. | |
// 2. If the module is native: call `NativeModule.require()` with the | |
// filename and return the result. | |
// 3. Otherwise, create a new module for the file and save it to the cache. | |
// Then have it load the file contents before returning its exports | |
// object. | |
Module._load = function(request, parent, isMain) { | |
if (parent) { | |
debug('Module._load REQUEST %s parent: %s', request, parent.id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Given a file name, pass it to the proper extension handler. | |
Module.prototype.load = function(filename) { | |
debug('load %j for module %j', filename, this.id); | |
assert(!this.loaded); | |
this.filename = filename; | |
this.paths = Module._nodeModulePaths(path.dirname(filename)); | |
var extension = path.extname(filename) || '.js'; | |
if (!Module._extensions[extension]) extension = '.js'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Native extension for .node | |
Module._extensions['.node'] = function(module, filename) { | |
return process.dlopen(module, path._makeLong(filename)); | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// DLOpen is process.dlopen(module, filename). | |
// Used to load 'module.node' dynamically shared objects. | |
void DLOpen(const FunctionCallbackInfo<Value>& args) { | |
Environment* env = Environment::GetCurrent(args); | |
uv_lib_t lib; | |
CHECK_EQ(modpending, nullptr); | |
if (args.Length() != 2) { | |
env->ThrowError("process.dlopen takes exactly 2 arguments."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org 0x7C00 ; BIOS loads our programm at this address | |
bits 16 ; We're working at 16-bit mode here | |
start: | |
cli ; Disable the interrupts | |
mov si, msg ; SI now points to our message | |
mov ah, 0x0E ; Indicate BIOS we're going to print chars | |
.loop lodsb ; Loads SI into AL and increments SI [next char] | |
or al, al ; Checks if the end of the string | |
jz halt ; Jump to halt if the end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brew install nasm | |
brew install qemu | |
curl https://gist.githubusercontent.com/ghaiklor/89e243a3463569480d01188c9e55e077/raw/460037f466928fd2e1d2e10473a579133434c094/boot.asm > boot.asm | |
nasm boot.asm -f bin -o boot.bin | |
qemu-system-i386 -fda boot.bin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
disk_read: | |
;; store all register values | |
pusha | |
push dx | |
;; prepare data for reading the disk | |
;; al = number of sectors to read (1 - 128) | |
;; ch = track/cylinder number | |
;; dh = head number | |
;; cl = sector number |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern void loader_main() { | |
for (int i = 0; i < 26; i++) { | |
char c = 0x41 + i; | |
asm( | |
"mov %0, %%al;" | |
"mov $0x0E, %%ah;" | |
"int $0x10;" | |
: | |
: "r" (c) |