-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathb_by_bootloader.c
More file actions
136 lines (123 loc) · 1.95 KB
/
b_by_bootloader.c
File metadata and controls
136 lines (123 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
* let bootloader load to memory
*/
asm(".code16gcc\n");
typedef unsigned char u8;
typedef unsigned int u32;
int i;
char* itoa(int n, char* str);
void print(const char *s)
{
while(*s)
{
__asm__ __volatile__ ("int $0x10" : : "a"(0x0E00 | *s), "b"(7));
s++;
}
}
#define DATA
const int A = 10;
#ifdef DATA
char data_str[]="data_string";
#endif
void write_mem8(u32 addr, u8 data); // assembly function.
int p()
{
write_mem8(0x4, 'Z'); // assembly function.
#if 0
int c=i+1;
char arr[10]="a";
char *s = arr;
#endif
#if 0
char stack_str[]="stack_string"; // need %ds = %ss
print("\r\n");
print(stack_str);
#endif
#if 0
const char *ro_str="ro_string"; // movl $0x000002f0, %ss:-4(%ebp)
print("\r\n");
print(ro_str);
#endif
#ifdef DATA
print("\r\n");
print(data_str);
#endif
#if 0
static char *s_str="static_point";
static char s_str_a[]="static_array";
print("\r\n");
print(s_str);
print("\r\n");
print(s_str_a);
#endif
//const char *str="test";
//volatile u8 *video_addr = (u8*)0xB8000;
//asm("movw $0xb000 %gs");
//*video_addr = 'a';
#if 0
s = itoa(c, s); // need %ds to 0
print("\r\n");
print(s);
return c;
#else
return 1;
#endif
}
#if 1
char* itoa(int n, char* str)
{
char digit[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char* p=str;
char* head=str;
int radix = 10;
// if(!p || radix < 2 || radix > 36)
// return p;
if (n==0)
{
*p++='0';
*p=0;
return str;
}
#if 0
if (radix == 10 && n < 0)
{
*p++='-';
n= -n;
}
#endif
while(n)
{
*p++=digit[n%radix];
n/=radix;
}
*p=0;
#if 1
for (--p; head < p ; ++head, --p)
{
char temp=*head;
*head=*p;
*p=temp;
}
#endif
return str;
}
#endif
#if 0
extern u32 __bss_start__;
extern u32 __bss_end__;
void init_bss()
{
u8 *bss=(u8*)__bss_start__;
*bss = 0x1;
*(bss+1) = 0x1;
*(bss+2) = 0x1;
*(bss+3) = 0x1;
#if 0
while (i!=(u8*)__bss_end__)
{
*i = 0x1;
++i;
}
#endif
}
#endif