-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
Binary file not shown.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <stddef.h> | ||
#include <stdint.h> | ||
#include <protos/chainload.h> | ||
#include <lib/part.h> | ||
#include <lib/config.h> | ||
#include <lib/blib.h> | ||
#include <drivers/disk.h> | ||
#include <drivers/vga_textmode.h> | ||
|
||
void chainload(void) { | ||
int part; { | ||
char buf[32]; | ||
if (!config_get_value(buf, 0, 32, "PARTITION")) { | ||
panic("PARTITION not specified"); | ||
} | ||
part = (int)strtoui(buf); | ||
} | ||
int drive; { | ||
char buf[32]; | ||
if (!config_get_value(buf, 0, 32, "DRIVE")) { | ||
panic("DRIVE not specified"); | ||
} | ||
drive = (int)strtoui(buf); | ||
} | ||
|
||
deinit_vga_textmode(); | ||
|
||
struct part p; | ||
get_part(&p, drive, part); | ||
|
||
read_partition(drive, &p, (void*)0x7c00, 0, 512); | ||
|
||
asm volatile ( | ||
// Jump to real mode | ||
"jmp 0x08:1f\n\t" | ||
"1: .code16\n\t" | ||
"mov ax, 0x10\n\t" | ||
"mov ds, ax\n\t" | ||
"mov es, ax\n\t" | ||
"mov fs, ax\n\t" | ||
"mov gs, ax\n\t" | ||
"mov ss, ax\n\t" | ||
"mov eax, cr0\n\t" | ||
"and al, 0xfe\n\t" | ||
"mov cr0, eax\n\t" | ||
"jmp 0:2f\n\t" | ||
"2:\n\t" | ||
"mov ax, 0\n\t" | ||
"mov ds, ax\n\t" | ||
"mov es, ax\n\t" | ||
"mov fs, ax\n\t" | ||
"mov gs, ax\n\t" | ||
"mov ss, ax\n\t" | ||
"push 0\n\t" | ||
"push 0x7c00\n\t" | ||
"retf\n\t" | ||
".code32\n\t" | ||
: | ||
: "d" (drive) | ||
); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef __PROTOS__CHAINLOAD_H__ | ||
#define __PROTOS__CHAINLOAD_H__ | ||
|
||
void chainload(void); | ||
|
||
#endif |