Skip to content

Commit 69fd003

Browse files
committed
Exec TicTacToe in protected mode with getch() as an INT
1 parent 2a06d44 commit 69fd003

File tree

14 files changed

+207
-74
lines changed

14 files changed

+207
-74
lines changed

Makefile

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,24 @@ kernel_core = $(BUILD_DIR)/kernel/core
3131

3232
# Apps
3333
app_calc = $(BUILD_APP)/calc
34-
app_tick_tac_toe = $(BUILD_APP)/tick_tac_toe
34+
app_tic_tac_toe = $(BUILD_APP)/tic_tac_toe
3535
app_dashboard = $(BUILD_APP)/dashboard
3636

3737
# Parameters
38-
BT_STAGE2_SECTOR_COUNT = 19 # In Hex
39-
KERNEL_MEMORY_LOCATION = 0xC000 # 16 bit for now
38+
SECTOR_START_BT_STAGE2 = 2
39+
SECTOR_COUNT_BT_STAGE2 = 19 # In Hex
40+
SECTOR_START_SHARED_LIBRARY = 1
41+
SECTOR_COUNT_SHARED_LIBRARY = 1
42+
SECTOR_START_KERNEL = 27
43+
SECTOR_COUNT_KERNEL = 33
44+
SECTOR_START_APP_TTT = 60
45+
SECTOR_COUNT_APP_TTT = 25
46+
SECTOR_START_APP_CALC = 85
47+
SECTOR_COUNT_APP_CALC= 25
48+
49+
MEMORY_LOCATION_KERNEL = 0xC000
50+
MEMORY_LOCATION_APP = 0x20000
51+
4052
SOURCE_SNAPSHOT="\"$$(git rev-parse --short HEAD)$$(git diff --quiet || echo '_unstaged')\""
4153

4254
# General Assumptions
@@ -50,35 +62,51 @@ images: $(image_vmdk)
5062

5163
binaries: $(bt_stage1) $(bt_stage2) $(kernel_core) $(rm_static)
5264

53-
$(image_vmdk): $(bt_stage1) $(bt_stage2) $(kernel_core) $(app_calc) $(app_tick_tac_toe) $(rm_static)
65+
$(image_vmdk): $(bt_stage1) $(bt_stage2) $(kernel_core) $(app_calc) $(app_tic_tac_toe) $(rm_static)
5466
dd bs=512 count=2 if=$(bt_stage1) of=$@
5567
/bin/echo -ne "\x55\xaa" | dd seek=510 bs=1 of=$@
5668
@echo "Stage 1 Size : " $$(stat -c %s $(bt_stage1))
57-
@echo "BT_STAGE2_SECTOR_START : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
58-
cat $(bt_stage2) >> $@
59-
@echo "Stage 2 Size : " $$(stat -c %s $(bt_stage2))
60-
@echo "Want BT_STAGE2_SECTOR_COUNT : 0x"$$(printf "%x\n" $$(( $$(stat -c %s $(bt_stage2)) / 512)) )
61-
@echo "Got BT_STAGE2_SECTOR_COUNT : 0x"$(BT_STAGE2_SECTOR_COUNT)
62-
63-
@echo "AppCalc Sector Start : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
64-
cat $(app_calc) >> $@
65-
@echo "AppCalc Sector Count : "$$(( $$(stat -c %s $(app_calc)) / 512))
66-
@echo "App Calc Size : " $$(stat -c %s $(app_calc))
67-
68-
@echo "App TickTacToe Sector Start : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
69-
cat $(app_tick_tac_toe) >> $@
70-
@echo "App TickTacToe Sector Count : "$$(( $$(stat -c %s $(app_tick_tac_toe)) / 512))
71-
@echo "App TickTacToe Size : " $$(stat -c %s $(app_tick_tac_toe))
7269

73-
@echo "Static Library Sector Start : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
70+
@echo "Static Library"
71+
@echo " Got SECTOR_START_SHARED_LIBRARY : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
72+
@echo " Want SECTOR_START_SHARED_LIBRARY : "$(SECTOR_START_SHARED_LIBRARY)
7473
cat $(rm_static) >> $@
75-
@echo "Static Library Sector Count : "$$(( $$(stat -c %s $(rm_static)) / 512))
76-
@echo "Static Library Size : " $$(stat -c %s $(rm_static))
74+
@echo " Got SECTOR_COUNT_SHARED_LIBRARY : "$$(( $$(stat -c %s $(rm_static)) / 512))
75+
@echo " Want SECTOR_COUNT_SHARED_LIBRARY : "$(SECTOR_COUNT_SHARED_LIBRARY)
76+
@echo " Size : " $$(stat -c %s $(rm_static))
7777

78-
@echo "Kernel Core Sector Start : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
78+
@echo "Boot Loader Stage 2"
79+
@echo " Got SECTOR_START_BT_STAGE2 : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
80+
@echo " Want SECTOR_COUNT_BT_STAGE2 : "$(SECTOR_START_BT_STAGE2)
81+
cat $(bt_stage2) >> $@
82+
@echo " Got SECTOR_COUNT_BT_STAGE2 : 0x"$$(printf "%x\n" $$(( $$(stat -c %s $(bt_stage2)) / 512)) )
83+
@echo " Want SECTOR_COUNT_BT_STAGE2 : 0x"$(SECTOR_COUNT_BT_STAGE2)
84+
@echo " Size : " $$(stat -c %s $(bt_stage2))
85+
86+
@echo "Kernel"
87+
@echo " Got SECTOR_START_KERNEL : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
88+
@echo " Want SECTOR_START_KERNEL : "$(SECTOR_START_KERNEL)
7989
cat $(kernel_core) >> $@
80-
@echo "Kernel Core Sector Count : "$$(( $$(stat -c %s $(kernel_core)) / 512))
81-
@echo "Kernel Core Size : " $$(stat -c %s $(kernel_core))
90+
@echo " Got SECTOR_COUNT_KERNEL : "$$(( $$(stat -c %s $(kernel_core)) / 512))
91+
@echo " Want SECTOR_COUNT_KERNEL : "$(SECTOR_COUNT_KERNEL)
92+
@echo " Size : " $$(stat -c %s $(kernel_core))
93+
94+
@echo "App TicTacToe"
95+
@echo " Got SECTOR_START_APP_TTT : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
96+
@echo " Want SECTOR_START_APP_TTT : "$(SECTOR_START_APP_TTT)
97+
cat $(app_tic_tac_toe) >> $@
98+
@echo " Got SECTOR_COUNT_APP_TTT : "$$(( $$(stat -c %s $(app_tic_tac_toe)) / 512))
99+
@echo " Want SECTOR_COUNT_APP_TTT : "$(SECTOR_COUNT_APP_TTT)
100+
@echo " Size : " $$(stat -c %s $(app_tic_tac_toe))
101+
102+
@echo "App Calc"
103+
@echo " Got SECTOR_START_APP_CALC : "$$(( $$(stat -c %s $(image_vmdk)) / 512 ))
104+
@echo " Want SECTOR_START_APP_CALC : "$(SECTOR_START_APP_CALC)
105+
cat $(app_calc) >> $@
106+
@echo " Got SECTOR_COUNT_APP_CALC : "$$(( $$(stat -c %s $(app_calc)) / 512))
107+
@echo " Want SECTOR_COUNT_APP_CALC : "$(SECTOR_COUNT_APP_CALC)
108+
@echo " Size : " $$(stat -c %s $(app_calc))
109+
82110
@echo "Image Size : " $$(stat -c %s $@)
83111

84112
debug_stage1: $(bt_stage1)
@@ -108,13 +136,20 @@ clean:
108136
# Fuzzy OS
109137
$(bt_stage1): $(SRC_BOOTLOADER)/stage1.asm $(SRC_BOOTLOADER)/constants.asm $(SRC_BOOTLOADER)/io.asm $(SRC_BOOTLOADER)/disk.asm
110138
mkdir -p $$(dirname $(bt_stage1))
111-
nasm -o $@ -f bin -i $(SRC_BOOTLOADER)/ -D BT_STAGE2_SECTOR_COUNT=$(BT_STAGE2_SECTOR_COUNT) $<
139+
nasm -o $@ -f bin -i $(SRC_BOOTLOADER)/ -D SECTOR_START_BT_STAGE2=$$((1+SECTOR_START_BT_STAGE2)) -D SECTOR_COUNT_BT_STAGE2=$(SECTOR_COUNT_BT_STAGE2) $<
112140
truncate --size=%512 $@
113141

114142
$(bt_stage2): $(SRC_BOOTLOADER)/stage2.asm $(SRC_BOOTLOADER)/stage2.c $(SRC_BOOTLOADER)/io.asm $(SRC_BOOTLOADER)/constants.asm $(SRC_REALMODE)/stub.asm $(BUILD_LIB_UTILS)/libutils_16 $(BUILD_DRIVERS)/display/libtm_bios $(BUILD_DRIVERS)/disk/libdisk_16
115143
mkdir -p $$(dirname $(bt_stage2))
116144
nasm -o $(BUILD_BOOTLOADER)/stage2_asm.o -f elf32 -i $(SRC_BOOTLOADER)/ -i $(SRC_REALMODE)/ $(SRC_BOOTLOADER)/stage2.asm
117-
gcc -m16 -fno-pie -c -Isrc -D KERNEL_MEMORY_LOCATION=$(KERNEL_MEMORY_LOCATION) -o $(BUILD_BOOTLOADER)/stage2_c.o $(SRC_BOOTLOADER)/stage2.c
145+
gcc -m16 -fno-pie -c -Isrc \
146+
-D SECTOR_START_SHARED_LIBRARY=$(SECTOR_START_SHARED_LIBRARY) \
147+
-D SECTOR_COUNT_SHARED_LIBRARY=$(SECTOR_COUNT_SHARED_LIBRARY) \
148+
-D SECTOR_START_KERNEL=$(SECTOR_START_KERNEL) \
149+
-D SECTOR_COUNT_KERNEL=$(SECTOR_COUNT_KERNEL) \
150+
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
151+
-D MEMORY_LOCATION_APP=$(MEMORY_LOCATION_APP) \
152+
-o $(BUILD_BOOTLOADER)/stage2_c.o $(SRC_BOOTLOADER)/stage2.c
118153
ld --oformat binary -m elf_i386 -Ttext 0x8000 --strip-all -o $@ $(BUILD_BOOTLOADER)/stage2_asm.o $(BUILD_BOOTLOADER)/stage2_c.o $(BUILD_LIB_UTILS)/libutils_16 $(BUILD_DRIVERS)/display/libtm_bios $(BUILD_DRIVERS)/disk/libdisk_16
119154
truncate --size=%512 $@
120155

@@ -127,7 +162,12 @@ $(kernel_core): $(SRC_KERNEL)/core.asm $(SRC_KERNEL)/core.c $(SRC_KERNEL)/essent
127162
mkdir -p $$(dirname $(kernel_core))
128163
nasm -o $(BUILD_KERNEL)/core_asm.o -f elf32 -i $(SRC_REALMODE)/ $(SRC_KERNEL)/core.asm
129164
nasm -o $(BUILD_KERNEL)/interrupts_asm.o -f elf32 $(SRC_KERNEL)/interrupts.asm
130-
gcc -m32 -fno-pie -c -Isrc -D KERNEL_MEMORY_LOCATION=$(KERNEL_MEMORY_LOCATION) -o $(BUILD_KERNEL)/core_c.o $(SRC_KERNEL)/core.c
165+
gcc -m32 -fno-pie -c -Isrc \
166+
-D SECTOR_START_APP_TTT=$(SECTOR_START_APP_TTT) \
167+
-D SECTOR_COUNT_APP_TTT=$(SECTOR_COUNT_APP_TTT) \
168+
-D MEMORY_LOCATION_KERNEL=$(MEMORY_LOCATION_KERNEL) \
169+
-D MEMORY_LOCATION_APP=$(MEMORY_LOCATION_APP) \
170+
-o $(BUILD_KERNEL)/core_c.o $(SRC_KERNEL)/core.c
131171
ld --oformat binary -m elf_i386 --trace -Ttext 0x0000 --strip-all -o $(kernel_core) $(BUILD_KERNEL)/core_asm.o $(BUILD_KERNEL)/core_c.o $(BUILD_KERNEL)/interrupts_asm.o $(BUILD_DRIVERS)/keyboard/libkeyboard $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga $(BUILD_LIB_DS)/libds $(BUILD_DRIVERS)/disk/libdisk
132172
truncate --size=%512 $(kernel_core)
133173

@@ -183,13 +223,14 @@ $(BUILD_LIB_UTILS)/libutils: $(SRC_LIB_UTILS)/output.c $(SRC_LIB_UTILS)/output.h
183223
mkdir -p $(BUILD_LIB_UTILS)/
184224
gcc -m32 -fno-pie -c -Isrc -o $(BUILD_LIB_UTILS)/output.o $(SRC_LIB_UTILS)/output.c
185225
gcc -m32 -fno-pie -c -Isrc -o $(BUILD_LIB_UTILS)/input.o $(SRC_LIB_UTILS)/input.c
226+
nasm -o $(BUILD_LIB_UTILS)/input_asm.o -f elf32 $(SRC_LIB_UTILS)/input.asm
186227
gcc -m32 -fno-pie -c -Isrc -o $(BUILD_LIB_UTILS)/string.o $(SRC_LIB_UTILS)/string.c
187228
gcc -m32 -fno-pie -c -Isrc -o $(BUILD_LIB_UTILS)/color.o $(SRC_LIB_UTILS)/color.c
188229
gcc -m32 -fno-pie -c -D__SOURCE_SNAPSHOT__=$(SOURCE_SNAPSHOT) -Isrc -o $(BUILD_LIB_UTILS)/panic_c.o $(SRC_LIB_UTILS)/panic.c
189230
nasm -o $(BUILD_LIB_UTILS)/panic_asm.o -f elf32 $(SRC_LIB_UTILS)/panic.asm
190231
gcc -m32 -fno-pie -c -Isrc -o $(BUILD_LIB_UTILS)/time_c.o $(SRC_LIB_UTILS)/time.c
191232
nasm -o $(BUILD_LIB_UTILS)/time_asm.o -f elf32 $(SRC_LIB_UTILS)/time.asm
192-
ar rc $@ $(BUILD_LIB_UTILS)/output.o $(BUILD_LIB_UTILS)/input.o $(BUILD_LIB_UTILS)/string.o $(BUILD_LIB_UTILS)/color.o $(BUILD_LIB_UTILS)/panic_c.o $(BUILD_LIB_UTILS)/panic_asm.o $(BUILD_LIB_UTILS)/time_c.o $(BUILD_LIB_UTILS)/time_asm.o
233+
ar rc $@ $(BUILD_LIB_UTILS)/output.o $(BUILD_LIB_UTILS)/input_asm.o $(BUILD_LIB_UTILS)/input.o $(BUILD_LIB_UTILS)/string.o $(BUILD_LIB_UTILS)/color.o $(BUILD_LIB_UTILS)/panic_c.o $(BUILD_LIB_UTILS)/panic_asm.o $(BUILD_LIB_UTILS)/time_c.o $(BUILD_LIB_UTILS)/time_asm.o
193234

194235
$(BUILD_LIB_DS)/libds: $(SRC_LIB_DS)/queue.h $(SRC_LIB_DS)/queue.c
195236
mkdir -p $(BUILD_LIB_DS)/
@@ -203,8 +244,8 @@ $(app_calc): $(app_entry) $(SRC_APP)/calc.c $(SRC_LIB_UTILS)/output.h $(SRC_LIB_
203244
ld --oformat binary -m elf_i386 -Ttext 0x2000 --strip-all -o $@ $(app_entry) $(BUILD_APP)/calc.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga
204245
truncate --size=%512 $@
205246

206-
$(app_tick_tac_toe): $(app_entry) $(SRC_APP)/tic_tac_toe.c $(SRC_LIB_UTILS)/output.h $(SRC_LIB_UTILS)/time.h $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga # And dependecies :/
207-
mkdir -p $$(dirname $(app_tick_tac_toe))
208-
gcc -m16 -fno-pie -c -Isrc -o $(BUILD_APP)/tic_tac_toe.o $(SRC_APP)/tic_tac_toe.c
209-
ld --oformat binary -m elf_i386 -Ttext 0x2000 --strip-all -o $@ $(app_entry) $(BUILD_APP)/tic_tac_toe.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga
247+
$(app_tic_tac_toe): $(app_entry) $(SRC_APP)/tic_tac_toe.c $(SRC_LIB_UTILS)/output.h $(SRC_LIB_UTILS)/input.h $(SRC_LIB_UTILS)/time.h $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga # And dependecies :/
248+
mkdir -p $$(dirname $(app_tic_tac_toe))
249+
gcc -m32 -fno-pie -c -Isrc -o $(BUILD_APP)/tic_tac_toe.o $(SRC_APP)/tic_tac_toe.c
250+
ld --oformat binary -m elf_i386 -Ttext 0x0 --strip-all -o $@ $(app_entry) $(BUILD_APP)/tic_tac_toe.o $(BUILD_LIB_UTILS)/libutils $(BUILD_DRIVERS)/display/libtm_vga
210251
truncate --size=%512 $@

src/app/tic_tac_toe.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@
22
#define BUILD_FOR_FUZZY
33
#ifndef BUILD_FOR_FUZZY
44
#else
5+
#include <lib/utils/input.h>
56
#include <lib/utils/output.h>
67
#include <lib/utils/time.h>
78
#include <lib/utils/string.h>
8-
char getch() {
9-
// Not Implemented.
10-
// Migrate binary to 32-bit.
11-
}
129
#endif
1310

1411
void console_init() {

src/bootloader/disk.asm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
; Not: sector is 1 based indexing here.
12
%macro disk_read 6
23
; Args: (sector_count, drive 8bit, cylinder 10bit, head 8bit, sector 6bit, write_add)
34
; check es

src/bootloader/stage1.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
print_string_ext bls1, bls1_len, 04, 04, C_WHITE, C_BLACK, 0
2525

2626
; Attempt to load Bootloader Stage 2 in Memory
27-
disk_read BT_STAGE2_SECTOR_COUNT, 80, 00, 00, 02, 8000
27+
disk_read SECTOR_COUNT_BT_STAGE2, 80, 00, 00, SECTOR_START_BT_STAGE2, 8000
2828
disk_success 80
2929
JNC label_bts2_loaded
3030
print_string_ext bls2_load_fail, bls2_load_fail_len, 06, 06, C_RED, C_BLACK, 0

src/bootloader/stage2.c

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <lib/utils/output.h>
44
#include <lib/utils/time.h>
55

6-
#define GDT_TABLE_SIZE 5
6+
#define GDT_TABLE_SIZE 7
77

88
#pragma pack(push, 1)
99
struct GDTReference {
@@ -45,21 +45,19 @@ void populate_gdt_table() {
4545
// Assumption DS = 0
4646
// Populate simple overlapping code and data segment.
4747

48-
// Kernel Memory Location: 0x100000
49-
5048
populate_gct_entry(
5149
&gdt_table[0],
5250
0,0,0,0);
5351
// Kernel Code Segment Selector
5452
populate_gct_entry(
5553
&gdt_table[1],
56-
KERNEL_MEMORY_LOCATION, 0x0fffffff,
54+
MEMORY_LOCATION_KERNEL, MEMORY_LOCATION_KERNEL+0xFFFF,
5755
0b0100, // 32-bit protected mode
5856
0x9a);
5957
// Kernel Data Segment Selector
6058
populate_gct_entry(
6159
&gdt_table[2],
62-
KERNEL_MEMORY_LOCATION, 0x0fffffff,
60+
MEMORY_LOCATION_KERNEL, MEMORY_LOCATION_KERNEL+0xFFFF,
6361
0b0100, // 32-bit protected mode
6462
0x92);
6563
// Absolute Code Segment Selector
@@ -74,6 +72,19 @@ void populate_gdt_table() {
7472
0, 0xfffff,
7573
0b0000, // 16-bit protected mode
7674
0x92);
75+
// Application Code Segment Selector
76+
populate_gct_entry(
77+
&gdt_table[5],
78+
MEMORY_LOCATION_APP, MEMORY_LOCATION_APP+0xFFFF,
79+
0b0100, // 32-bit protected mode
80+
0x9a);
81+
// Application Data Segment Selector
82+
populate_gct_entry(
83+
&gdt_table[6],
84+
MEMORY_LOCATION_APP, MEMORY_LOCATION_APP+0xFFFF,
85+
0b0100, // 32-bit protected mode
86+
0x92);
87+
7788

7889
gdtr = (struct GDTReference*)_low_get_gdtr_address();
7990
gdtr->base_address = (int)gdt_table;
@@ -94,14 +105,14 @@ void populate_gdt_table() {
94105

95106
void load_kernel() {
96107
// As we are in real mode with DS as 0
97-
// KERNEL_MEMORY_LOCATION should be within 16 bit for now.
98-
int err = load_sectors(KERNEL_MEMORY_LOCATION, 0x80, DISK_KERNEL_SECTOR_START, DISK_KERNEL_SECTOR_COUNT);
108+
// MEMORY_LOCATION_KERNEL should be within 16 bit for now.
109+
int err = load_sectors(MEMORY_LOCATION_KERNEL, 0x80, SECTOR_START_KERNEL, SECTOR_COUNT_KERNEL);
99110
if(err) {
100111
print_line("Failed to load kernel in memory: ");
101112
print_int(err);
102113
label_exit();
103114
} else {
104-
print_memory_hex((char*)KERNEL_MEMORY_LOCATION, 16);
115+
print_memory_hex((char*)MEMORY_LOCATION_KERNEL, 16);
105116
}
106117
}
107118

@@ -117,7 +128,7 @@ void load_calc() {
117128
}
118129

119130
void load_static_library() {
120-
int err = load_sectors(0x7E00, 0x80, 76, 1);
131+
int err = load_sectors(0x7E00, 0x80, SECTOR_START_SHARED_LIBRARY, SECTOR_COUNT_SHARED_LIBRARY);
121132
if(err) {
122133
print_line("Failed to load calc in memory.");
123134
print_int(err);

src/drivers/disk/disk.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#pragma once
22

3-
#define DISK_KERNEL_SECTOR_START 77
4-
#define DISK_KERNEL_SECTOR_COUNT 33
5-
63
int load_sectors(unsigned int address,
74
unsigned char drive,
85
unsigned int sector_index, // 1-based

src/kernel/core.asm

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
[BITS 32]
44

55
extern kernel_core_entry
6+
extern reload_idt_table
67
global __low_va_args
8+
global call_main
79

810
[SECTION .text]
911
; protected mode real entry point.
@@ -19,7 +21,14 @@ global __low_va_args
1921
get_protected_mode_entry
2022
cmp eax, 0
2123
je kernel_core_entry
22-
unshelve_protected_mode_jump_entry_address_fpm
24+
25+
unshelve_protected_mode_and_ret_entry_address
26+
push eax
27+
call reload_idt_table
28+
STI
29+
pop eax
30+
jmp eax
31+
2332

2433
__low_va_args:
2534

@@ -28,3 +37,46 @@ global __low_va_args
2837
add esi, 4
2938
mov eax, [ebp + esi]
3039
ret
40+
41+
call_main:
42+
push ebp
43+
mov ebp, esp
44+
45+
mov eax, [ebp + 0x8] ; (argc)
46+
mov ebx, [ebp + 0xc] ; (argv)
47+
48+
mov eax, esp
49+
mov [kernel_saved_stack_top], eax
50+
51+
; Preparing for exec.
52+
53+
mov ax, 0x30
54+
mov es, ax
55+
mov ss, ax
56+
mov ds, ax
57+
mov fs, ax
58+
mov gs, ax
59+
60+
mov eax, 0xFFFF
61+
mov esp, eax
62+
call 0x28:0x0000
63+
; eax should contain the program return value.
64+
65+
; Returned from exec.
66+
67+
mov bx, 0x10
68+
mov es, bx
69+
mov ss, bx
70+
mov ds, bx
71+
mov fs, bx
72+
mov gs, bx
73+
74+
mov ebx, [kernel_saved_stack_top]
75+
mov esp, ebx
76+
77+
mov esp, ebp
78+
pop ebp
79+
ret
80+
81+
[SECTION .data]
82+
kernel_saved_stack_top db ' '

0 commit comments

Comments
 (0)