Files
x86-bare-metal-examples/bios_initial_state.S

65 lines
1.2 KiB
ArmAsm
Raw Normal View History

2018-12-04 09:46:27 +00:00
/* https://github.com/cirosantilli/x86-bare-metal-examples#bios-initial-state */
2015-10-05 16:55:48 +02:00
#include "common.h"
.macro INITIAL_STORE x
mov %\()\x, \x
.endm
.macro INITIAL_DATA x
2015-10-28 18:36:31 +01:00
\x: .skip 2
\x\()s: .ascii "\x = \0"
.endm
.macro INITIAL_PRINT x
PRINT_STRING $\x\()s
2015-10-28 18:36:31 +01:00
PRINT_BYTES $\x, $2
2015-10-05 16:55:48 +02:00
PRINT_NEWLINE
.endm
2015-10-05 16:55:48 +02:00
/* Indispensable initialization.
* This initialization is a bit redundant with BEGIN,
* and does dirty some registers, but I haven't found a better option.
*/
2015-10-28 18:36:31 +01:00
.code16
cli
xor %ax, %ax
mov %ax, %ds
/* We want our data do be before STAGE2,
* or it will get overwritten during the load.
*/
2015-10-28 18:36:31 +01:00
jmp after_data
2015-10-06 12:27:24 +02:00
2015-10-28 18:36:31 +01:00
.irp reg, ax, bx, cx, dx, cs, ds, es, fs, gs, ss
INITIAL_DATA \reg
.endr
cr0: .long 0
cr0s: .ascii "cr0 = \0"
after_data:
.irp reg, ax, bx, cx, dx, cs, ds, es, fs, gs, ss
INITIAL_STORE \reg
.endr
/* Does not have a 16-bit mov version. */
mov %cr0, %eax
mov %eax, cr0
/* We delay a full BEGIN as late as possible
* to mess with less initial state.
*/
2015-10-06 12:27:24 +02:00
BEGIN
STAGE2
2015-10-05 16:55:48 +02:00
2015-10-28 18:36:31 +01:00
.irp reg, ax, bx, cx, dx, cs, ds, es, fs, gs, ss
INITIAL_PRINT \reg
.endr
PRINT_STRING $cr0s
2015-10-28 18:36:31 +01:00
PRINT_BYTES cr0, $4
PRINT_NEWLINE
2015-10-05 16:55:48 +02:00
2015-10-28 18:36:31 +01:00
hlt