. = ALIGN(4);
_ldr_main_start = .;
+ _ldr_main_end = _ldr_main_start + _main_size;
/* main program will be moved to 2MB by the loader */
. = 2M;
- _main_start = .;
- .startup : { * (.startup); }
- .text : { * (.text*); }
- .rodata : { * (.rodata*); }
- .data : { * (.data*); }
+ main ALIGN(4): AT (_ldr_main_start) {
+ _main_start = .;
+ * (.startup);
+ * (.text*);
+ * (.rodata*);
+ * (.data*);
- .bss ALIGN(4): {
+ . = ALIGN(4);
_bss_start = .;
* (.bss*);
* (COMMON);
. = ALIGN(4);
_bss_end = .;
+ _bss_size = _bss_end - _bss_start;
}
- _bss_size = SIZEOF(.bss);
+ . = ALIGN(4);
_main_size = . - _main_start;
_mem_start = .;
}
cld
mov esi, _ldr_main_start
mov edi, _main_start
- lea ecx, [_main_size + 3]
+ mov ecx, _main_size + 3
shr ecx, 2
rep movsd
mov ax, 10h
mov ds, ax
mov ss, ax
- mov esp, 200000h
+ mov esp, _main_start
call 8:startup
and ax, 0xfffe
mov cr0, eax
.jmpcs16:
- jmp 42h:.loadcs16 ; 42 seg is modifed at the start (TODO)
+ jmp 42h:.loadcs16 ; 42 seg is modifed at the start
.loadcs16:
mov ax, fs
mov ds, ax
gdt: ; 0: null segment
dd 0
dd 0
- ; 1: code - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd
+ ; 1: code - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:code/non-conf/rd (sel: 8)
dd 0000ffffh
dd 00cf9a00h
- ; 2: data - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw
+ ; 2: data - 0/lim:4g, G:4k, 32bit, avl, pres|app, dpl:0, type:data/rw (sel: 10h)
dd 0000ffffh
dd 00cf9200h
- ; 3: tmp code (will set base before entering pmode)
+ ; 3: tmp code (will set base before entering pmode) (sel: 18h)
dd 0000ffffh
dd 00cf9a00h
- ; 4: tmp data (will set base before entering pmode)
+ ; 4: tmp data (will set base before entering pmode) (sel: 20h)
dd 0000ffffh
dd 00cf9200h
- ; 5: return to real-mode 16bit code segment
+ ; 5: return to real-mode 16bit code segment (sel: 28h)
dd 0000ffffh
dd 00009a00h