Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
octopOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
weip00
octopOS
Commits
ca8cd9fa
Commit
ca8cd9fa
authored
3 years ago
by
weip00
Browse files
Options
Downloads
Patches
Plain Diff
Add Comments on printf
parent
fc46c27a
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
apps/demo.c
+1
-1
1 addition, 1 deletion
apps/demo.c
drivers/dbgu.c
+1
-1
1 addition, 1 deletion
drivers/dbgu.c
interfaces.h
+5
-0
5 additions, 0 deletions
interfaces.h
libs/printf.c
+21
-3
21 additions, 3 deletions
libs/printf.c
with
28 additions
and
5 deletions
apps/demo.c
+
1
−
1
View file @
ca8cd9fa
...
...
@@ -22,4 +22,4 @@ void io_demo() {
printf
(
"end of demo loop.
\n
"
);
printf
(
"And heres what happnes with unknown formats:
\n
%a %b %% %f
\n
"
,
1
,
2
,
3
,
4
);
printf
(
"done. (press ^a then x to quit qemu)"
);
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
drivers/dbgu.c
+
1
−
1
View file @
ca8cd9fa
...
...
@@ -76,4 +76,4 @@ sequence_io_status dbgu_read(uint len, byte* buff) {
else
out
.
err
=
0
;
return
out
;
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
interfaces.h
+
5
−
0
View file @
ca8cd9fa
...
...
@@ -4,6 +4,11 @@
#include
"default.h"
// Utilites, maybe move somewhere else
/**
* Struct to hold the result of multiple sequential IO operations, as we don't have errno
* io: number of sucessfull io operations
* err: error on the (io+1)th operation or 0 if all requests were sucessfull
*/
typedef
struct
{
uint
io
;
int
err
;
...
...
This diff is collapsed.
Click to expand it.
libs/printf.c
+
21
−
3
View file @
ca8cd9fa
...
...
@@ -18,6 +18,23 @@ sequence_io_status printf(char* format, ...) {
.
err
=
0
};
sequence_io_status
hw_out
;
/*
* How this works:
* format points at remainder of the format string,
* cursor runs ahead and points at whatever is going to be formatted next.
*
* the loop then explosts the fact that a format sting is a sequence of %?
* with constant strings in between. Thus it loops as follows:
*
* while format left:
* write constant string
* if format left:
* pop arg
* format arg
* write arg
* end:
* free(args)
*/
while
(
*
cursor
)
{
// run to the next '%'
for
(
cursor
=
format
;
*
cursor
&&
*
cursor
!=
'%'
;
++
cursor
);
...
...
@@ -27,9 +44,9 @@ sequence_io_status printf(char* format, ...) {
if
(
out
.
err
||
!*
cursor
)
goto
end
;
++
cursor
;
++
cursor
;
// cursor is at a '%' here, the foramt char is next.
switch
(
*
cursor
)
{
case
0
:
case
0
:
// format string ends on a '%', we're friendly and print it.
hw_out
=
dbgu_write
(
1
,
cursor
-
1
);
break
;
case
'c'
:
...
...
@@ -50,6 +67,7 @@ sequence_io_status printf(char* format, ...) {
case
'x'
:
/* fall through */
case
'p'
:
// write the number into the buffer, back to front.
pos
=
9
;
for
(
u32
num
=
va_arg
(
args
,
u32
);
num
;
num
>>=
4
,
--
pos
)
buff
[
pos
]
=
lookuptable
[
num
&
0xF
];
...
...
@@ -67,4 +85,4 @@ sequence_io_status printf(char* format, ...) {
end:
va_end
(
args
);
return
out
;
}
\ No newline at end of file
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment